#include<stdio.h>
#include<math.h>

int result;

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

int search(int n,int data[],int i,int a,int b){

  if(i<n){
    search(n,data,i+1,a+data[i],b);
    search(n,data,i+1,a,b+data[i]);
  }
  else if(abs(a-b)<result)result=abs(a-b);

  return result;
}