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

int n , v[20];

map<int,int> memo[20];

int f(int pos , int sum){
	return pos == n ? abs(sum) : memo[pos].count(sum) ? memo[pos][sum] : memo[pos][sum] = min( f(pos+1,sum+v[pos] ) , f(pos+1,abs(sum-v[pos])) );
}

int main(){
	while(cin >> n && n){
		for(int i = 0 ; i < n ; i++) cin >> v[i] , memo[i].clear() ;
		cout << f(0,0) << endl;
	}
}