#include <iostream>
using namespace std;

int n;
int data[20];

int abs(int x) {
  return (x > 0) ? x : -x;
}
int rec(int p, int A, int B) {
  static int min;
  if(p == 0) min = 999999;
  if(p == n) {
    int temp = abs(A-B);
    if(temp < min) min = temp;
    return 0;
  }
  rec(p+1, A+data[p], B);
  rec(p+1, A, B+data[p]);
  return min;
}

int main() {
  while(1) {
    cin >> n;
    if(n == 0) break;
    for(int i = 0; i < n; i++) {
      cin >> data[i];
    }
    cout << rec(0, 0, 0) << endl;
  }
  return 0;
}