#include<bits/stdc++.h>

using namespace std;

int calc_diff(vector<int>& strength, int team) {

  int team_a = 0, team_b = 0;

  for (int i = 0; i < (int) strength.size(); i++) {
    if (team & 1) {
      team_a += strength[i];
    } else {
      team_b += strength[i];
    }
    team >>= 1;
  }

  return abs(team_a - team_b);
}

int main() {

  int size;
  while (cin >> size && size != 0) {

    vector<int> strength(size);
    for (int i = 0; i < size; i++) {
      cin >> strength[i];
    }

    int minDiff = INT_MAX;
    for (int i = 0; i < (1<<size); i++) {
      minDiff = min(minDiff, calc_diff(strength, i));
    }

    cout << minDiff << endl;
  }
  
  return 0;
}