#include <stdio.h>
#include <stdlib.h>

int main(void) {
	int member_num;
	int members[20];
	int i_max;
	int i,j;
	int a,b,now,min;
	while(1) {
		scanf("%d",&member_num);
		if(member_num==0)break;
		for(i=0;i<member_num;i++) {
			scanf("%d",&members[i]);
		}
		i_max=1<<(member_num-1);
		min=0x7fffffff;
		for(i=0;i<i_max;i++) {
			for(a=b=0,j=0;j<member_num;j++) {
				if(i & (1<<j))a+=members[j]; else b+=members[j];
			}
			now=abs(a-b);
			if(now<min)min=now;
		}
		printf("%d\n",min);
	}
	return 0;
}