#include<bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
int a;
while(cin>>a,a){
	int sum=0;
	vector<vector<int>>c(a+1);
	c[0].push_back(0);
	for(int b=0;b<a;b++){
		int e;
		scanf("%lld",&e);
		sum+=e;
		for(int d=0;d<c[b].size();d++){
			c[b+1].push_back(c[b][d]);
			c[b+1].push_back(c[b][d]+e);
		}
	}
	int MIN=LLONG_MAX/3;
	for(int x=0;x<c[a].size();x++){
		MIN=min(MIN,abs(c[a][x]-(sum-c[a][x])));
	}
	printf("%lld\n",MIN);
}
}