#include <cstdio>
using namespace std;

int main(void)
{
	int n;
	long long num, sum = 0, max = -100001;
	
	scanf("%d",&n);
	for(int f1 = 0; f1 < n; f1++){
		scanf("%lld",&num);
		sum += num;
		if(max < sum)
		{
			max = sum;
		}
	}

	printf("%lld\n", max);
	return 0;
}