#include <iostream>
#include <cstdlib>
using namespace std;

int n,a[21],mini;

void rec(int idx,int sum1,int sum2){
  if(idx == n){
    if(mini > abs(sum1 - sum2)) mini = abs(sum1 - sum2);
    return;
  }
  rec(idx+1,sum1+a[idx],sum2); rec(idx+1,sum1,sum2+a[idx]);
}


int main(){
  while(cin >> n,n){
    mini = (2 << 28);
    for(int i=0;i<n;i++) cin >> a[i];
    rec(0,0,0);
    cout << mini << endl;
  }
}