#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
#define INF (1<<25)
 
int main(){
	int n , v[20] , X[41] , Y[41] , top;
	while(scanf("%d\n",&n)&& n){
		int dp2[21] = {0};
		for(int i = 0 ; i < n ; i++) scanf("%d",&v[i]);
		sort(v,v+n,greater<int>());
		for(int i = n-1 ; i >= 0 ; i--) dp2[i] = dp2[i+1] + v[i];
		
		int ans = INF;
		
		top = 0;
		X[top] = Y[top] = 0;
		while(~top){
			int pos = X[top] , sum = Y[top]; top--;
			if(pos==n) ans = min(ans,sum);
			else{
				if( sum >= dp2[pos] && ans <= sum-dp2[pos] ) continue; // ツ枝ツ偲ォ
				X[++top] = pos+1 , Y[top]   = sum+v[pos];
				X[++top] = pos+1 , Y[top]   = abs(sum-v[pos]);
			}
		}
		printf("%d\n",ans);
	}
}