#include<stdio.h>
int n;
int p[20];
int abs(int x) {
	return ((x > 0) - (x < 0)) * x;
}
int min(int a, int b) {
	if (a <= b) return a;
	else return b;
}
int solve(int i, int sa, int sb) {
	int ssa, ssb;
	if (i >= n) return abs(sa - sb);
	ssa = solve(i + 1, sa + p[i], sb);
	ssb = solve(i + 1, sa, sb + p[i]);
	return min(ssa, ssb);
}
int main() {
	int i;
	while (1) {
		scanf("%d", &n);
		if (!n) break;
		for (i = 0; i < n; i ++) scanf("%d", &p[i]);
		printf("%d\n", solve(0, 0, 0));
	}
	return 0;
}