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