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

int n, sum, ans;
int t[22];
bool used[22];

void solve(int idx, int t_sum){
  if(idx == n){
    ans = min(ans, abs(t_sum - (sum - t_sum)));
    return;
  }

  solve(idx + 1, t_sum);
  solve(idx + 1, t_sum + t[idx]);
}

int main(){
  while(cin >> n, n){
    sum = 0;
    for(int i = 0; i < n; i++){
      cin >> t[i];
      sum += t[i];
    }

    ans = INT_MAX;
    memset(used, 0, sizeof(used));
    solve(0, 0);

    cout << ans << endl;
  }
}