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

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