#include <set>
#include <cstdio>
#include <cstdlib>
#include <climits>

#define REP(i,n) for(int i=0; i<(int)(n); i++)

inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

int v[20];

int main(){
  while(int n = getInt()){
    int ans = INT_MAX;

    REP(i, n) v[i] = getInt();
    REP(i, (1 << n)){
      int a[2] = { 0, 0 };

      REP(j, n){
	a[(i & (1 << j)) == 0] += v[j];
      }

      ans = min(ans, std::abs(a[0] - a[1]));
    }

    printf("%d\n", ans);
  }
  return 0;
}