#include <iostream>
#include <cmath>

using namespace std;

int n, mem_index = 0, fight_strength[20] = {0}; //登録者数、何番目の登録か、登録者の戦闘力

int my_min(int now, int a_sum, int b_sum)
{
	if(now == n) return abs(a_sum - b_sum);

	int min_a = my_min(now + 1, a_sum + fight_strength[now], b_sum),
	    min_b = my_min(now + 1, a_sum, b_sum + fight_strength[now]);

	if(min_a > min_b)
		return min_b;
	else if(min_a < min_b)
		return min_a;
	else
		return min_a;
}

int main(void)
{
	while(true)
	{
		cin >> n;
		if(n == 0) break;
		while(mem_index < n)
		{
			cin >> fight_strength[mem_index];
			mem_index++;
		}

		cout << my_min(0, 0, 0) << endl;
		mem_index = 0;
	}
	return 0;
}