#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;

int data[99];

int solve(int n, int a, int b){

  if(!n) return abs(a-b);

  return min(solve(n-1, a+data[n], b), solve(n-1, a, b+data[n]));
}

int main(){

  int n;
  while(cin >> n, n){
    for(int i=1;i<=n;i++) cin >> data[i];
    cout << solve(n, 0, 0) << endl;
  }

}