#include <iostream>
#include <vector>

using namespace std;
int abs(int a)
{
	return(a < 0 ? -a : a);
}

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<int> Vec(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> Vec[i];
		}
		int mi = 999999999;
		int a = 0;
		int b = 0;
		for(int i = 0; i < (1 << n); ++i)
		{
			a = b = 0;
			for(int j = 0; j < n; ++j)
			{
				if((1 << j) & i)
				{
					a += Vec[j];
				}
				else
				{
					b += Vec[j];
				}
			}
			mi = min(mi, abs(a - b));
		}
		cout << mi << endl;
	}
}

int main()
{
	solve();
	return(0);
}