#include<iostream>
using namespace std;

int main(){
	int n;
	int a;
	int sum;
	cin >> n;
	while(n){
		cin >> sum;
		for(int i=0;i<n;i++){
			cin >> a;
			if(sum < a){
				sum = a;
			}else{
				sum += a;
			}
		}
		cout << sum << endl;
		cin >> n;
	}
	return 0;
}