#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
const int INF =1e+9;
int a[30];
int n;
int ans;
void dfs(int diff,int k){
  if(k == n){
    ans = min(ans,abs(diff));
  }else {
    dfs(diff+a[k],k+1);
    dfs(diff-a[k],k+1);
  }
}

int main()
{
  while(cin>>n,n){
    for(int i = 0;i < n;i++){
      cin >>a[i];
    }
    ans = INF;
    dfs(0,0);
    cout <<ans<<endl;
  }
  return 0;
}