#include <stdio.h>

int min, n, sum, a[100];

void solve(int i, int gon)
{
	int m;
	
	if (i == n - 1){
		m = gon * 2 - sum;
		
		if (m < 0){
			m *= -1;
		}
		if (min > m){
			min = m;
		}
		return;
	}
	
	solve(i + 1, gon + a[i]);
	solve(i + 1, gon);
}

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