#include<cstdio>
#include<algorithm>
#include<iostream>

#define reps(i,f,n) for(int i = f; i < int(n); i++)
#define rep(i,n) reps(i,0,n)

using namespace std;


int main(void){
	int n;
	while(cin >> n){
		int ans = 100000000;
		int a[32]={0};
		if(!n)break;
		rep(i,n)cin >> a[i];
		
		rep(i,1<<n){
			int ga = 0,gb = 0;
			for(int j = 1,index = 0; j < 1<<n; j = j<<1,index++){
				if(i&j){
					ga+=a[index];
				}else{
					gb+=a[index];
				}
			}
			ans = min(abs(ga-gb), ans);
		}
		
		printf("%d\n", ans);
	}
}