#include <stdio.h>
#include <math.h>

int min;

int dfs(int *a, int n, int i, int ta, int tb)
{
	if (i == n){
		if (abs(ta - tb) < min){
			min = abs(ta - tb);
		}
	}
	else {
		dfs(a, n, i + 1, ta + a[i], tb);
		dfs(a, n, i + 1, ta, tb + a[i]);
	}
	
	return (min);
}

int main(void)
{
	int n;
	int a[20];
	int ta, tb;
	int i, j;
	
	while (1){
		scanf("%d", &n);
		
		if (n == 0){
			break;
		}
		for (i = 0; i < n; i++){
			scanf("%d", &a[i]);
		}
		min = 1000000000;
		printf("%d\n", dfs(a, n, 0, 0, 0));
	}
	
	return (0);
}