#include using namespace std; typedef long long int ll; typedef pair P; typedef pair Pll; typedef vector Vi; typedef tuple T; #define FOR(i,s,x) for(int i=s;i<(int)(x);i++) #define REP(i,x) FOR(i,0,x) #define ALL(c) c.begin(), c.end() #define DUMP( x ) cerr << #x << " = " << ( x ) << endl int dp[1024]; int V[1024]; int main() { // use scanf in CodeForces! cin.tie(0); ios_base::sync_with_stdio(false); int N; cin >> N; REP(i, N) cin >> V[i]; int sushi = 0; REP(i, N) { dp[i+1] = max(dp[i], sushi + V[i]); sushi = max(sushi, dp[i]); } cout << dp[N] << endl; return 0; }