#include<iostream>
#include<algorithm>
using namespace std;

long long S[5010];

int main(){
	long long a, maximum = -1000000;
	int i = 1;
	S[0] = 0;
	while (cin >> a, a){
		S[i] = S[i - 1] + a;
		i++;
	}

	for (int n = 0; n < i; n++)
		for (int m = n + 1; m < i; m++){
			maximum = max(maximum, S[m]-S[n]);
		}
	cout << maximum << endl;
}