#include <cstdio>
#include <algorithm>

using namespace std;

int A[32];

int getMini(int idx, int costA, int costB)
{
	if (idx == -1) return (abs(costA - costB));
	
	return (min(getMini(idx - 1, costA + A[idx], costB),
				getMini(idx - 1, costA, costB + A[idx])));
}

int main()
{
	int n;
	
	while (scanf("%d", &n) && n){
		for (int i = 0; i < n; i++){
			scanf("%d", A + i);
		}
		
		printf("%d\n", getMini(n - 1, 0, 0));
	}
	
	return (0);
}