#include <iostream>
using namespace std;
const int N = 1010;
int a[N];
int dp[N];
int main(){
int n;
cin >> n;
for (int i = 1; i <= n; i ++ ){
cin >> a[i];
dp[i] = a[i];
}
for (int i = 1; i <= n; i ++ ){
for (int j = 1; j < i; j ++ ){
if(a[i] > a[j]){
dp[i] = max(dp[i], dp[j]+a[i]);
}
}
}
int ans = a[1];
for (int i = 1; i <= n; i ++ ){
ans = max(ans, dp[i]);
}
cout << ans;
return 0;
}