#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 ab(int n){return n<0?-n:n;}
inline int min(int a,int b)
{
  return a<b?a:b;
}
void solve(int p,int x,int y)
{
  if(p==n){
    res=min(res,ab(x-y));
    return;
  }
  solve(p+1,x+a[p],y);
  solve(p+1,x,y+a[p]);
}
int main(void)
{
  int i;
  for(;;){
    scanf("%d",&n); if(!n)break;
    rep(i,n) scanf("%d",a+i);
    res=INFTY;
    solve(0,0,0);
    printf("%d\n",res);
  }
  return 0;
}