#include <stdio.h>
#include <math.h>
int n;
int ary[20];
int min(int a,int b){
	if(a<b)return a;
	else return b;
	}
int solve(int a,int b,int k){
	if(n==k){
		return abs(a-b);
		}
	return min(solve(a+ary[k],b,k+1),solve(a,b+ary[k],k+1));

	}
int main(){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		int i;
		for(i=0;i<n;i++){
			scanf("%d",&ary[i]);
			}
		printf("%d\n",solve(0,0,0));
		}
	return 0;
	}