#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define REP(i,m,n) for(i=(m);i<((int)(n));i++)
#define rep(i,n) REP(i,0,n)
#define INFTY (1<<21)
#define LLINFTY (1LL<<53)
typedef long long ll;
typedef unsigned long long ull;
int n,a[20],res;
int s1[111111],s2[111111],s3[111111];
int ab(int n){return n<0?-n:n;}
inline int min(int a,int b)
{
  return a<b?a:b;
}
void solve()
{
  int x,y,c; x=y=c=0;
  int sp=0;
  s1[sp]=s2[sp]=s3[sp]=0; sp++;
  while(sp){
    sp--;
    x=s1[sp];
    y=s2[sp];
    c=s3[sp];
    if(c==n){
      res=min(res,ab(x-y));
      continue;
    }
    s1[sp]=x+a[c];
    s2[sp]=y;
    s3[sp]=c+1;
    sp++;
    s1[sp]=x;
    s2[sp]=y+a[c];
    s3[sp]=c+1;
    sp++;
  }
}
int main(void)
{
  int i;
  for(;;){
    scanf("%d",&n); if(!n)break;
    rep(i,n) scanf("%d",a+i);
    res=INFTY;
    solve();
    printf("%d\n",res);
  }
}