#include <stdio.h>
#include <limits.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#define swap(type, x, y) do{type temp = x; x = y; y = temp;}while(0);
using namespace std;
void quick_sort(long long int x[], int left, int right);
int main(void) {
    int num;
    
    while(1) {
        scanf("%d", &num);
        if(num == 0) break;
        
        long long int sum[num + 1];
        int i, value;
        
        for(i = 0; i < num + 1; i++) {
            sum[i] = 0;
        }
        
        for(i = 0; i < num; i++) {
            scanf("%d", &value);
            sum[i + 1] += sum[i] + value;
        }
        quick_sort(sum, 1, num);
        
        cout << sum[1] << endl;
    }
    
    return(0);
}

void quick_sort(long long int x[], int left, int right) {
    int i, j;
    long long int pivot;
    
    i = left;
    j = right;
    pivot = x[(left + right) / 2];
    
    while(1) {
        while(x[i] > pivot) i++;
        while(x[j] < pivot) j--;
        
        if(i >= j) break;
        
        swap(long long int, x[i], x[j]);
        i++;
        j--;
    }
    if(i - 1 > left) quick_sort(x, left, i - 1);
    if(j + 1 < right) quick_sort(x, j + 1, right);
}