#include<stdio.h>
int a,b,n,t[20];
R(int r,int s,int j){
int i=j,o;
if(!r)if(b>abs(a-2*s))b=abs(a-2*s);
if(r<=0||n<=j)return;
for(;i<=n-r;i++)R(r-1,s+t[i],i+1);
}
main(){
int i;
while(scanf("%d",&n)&&n){
for(i=a=0;i<n;i++){scanf("%d",&t[i]);a+=t[i];}
b=a;
for(i=0;i<=n;i++)R(i,0,0);
printf("%d\n",b);
}
return 0;
}