#include <stdio.h>

int mem[25], s, n;
int min = -1;

void solve(int x, int A)
{
	int B;
	int sa;
	
	if (x == n){
		B = s - A;
		if( A > B){
			sa = A - B;
		}
		else {
			sa = B - A;
		}
		if (min == -1){
			min = sa;
		}
		if (min > sa){
			min = sa;
		}
		return;
	}
	
	solve(x + 1, A + mem[x]);
	solve(x + 1, A);
}

int main(void)
{
	int i;
	
	while (1){
		
		s = 0;
		
		scanf("%d", &n);
		
		if (n == 0){
			break;
		}
		for (i = 0; i < n; i++){
			scanf("%d", &mem[i]);
			s += mem[i];
		}
		solve(0, 0);
		printf("%d\n", min);
		min = -1;
	}
	return (0);
}