#include <stdio.h>
#include <limits.h>

int players[36];
int min, n;

void dfs(int power, int no, int total)
{
	if (no == n){
		min = min > abs(power - total) ? abs(power - total) : min; 
		return;
	}
	dfs(power + players[no], no + 1, total - players[no]);
	dfs(power, no + 1, total);
}

int main(void)
{
	while (scanf("%d", &n), n){
		int sum, i;
		
		sum = 0;
		for (i = 0; i < n; i++){
			scanf("%d", players + i);
			sum += players[i];
		}
		min = INT_MAX;
		dfs(0, 0, sum);
		printf("%d\n", min);
	}
	return (0);
}