def solve(a,i,sa,sb):

	if 2*sa >= all: return 2*sa-all

	if 2*sb >= all: return 2*sb-all

	return min(solve(a,i+1,sa+a[i],sb),solve(a,i+1,sa,sb+a[i]))

	

while 1:

	n = eval(input())

	if n == 0: break

	a = sorted(map(int,input().split()))

	all = sum(a)

	print(solve(a,1,a[0],0))
def solve(a,i,sa,sb):

	if 2*sa >= all: return 2*sa-all

	if 2*sb >= all: return 2*sb-all

	return min(solve(a,i+1,sa+a[i],sb),solve(a,i+1,sa,sb+a[i]))

	

while 1:

	n = eval(input())

	if n == 0: break

	a = sorted(map(int,input().split()))[::-1]

	all = sum(a)

	print(solve(a,1,a[0],0))
def solve(a, i, sa, sb):
    if 2 * sa >= all:
        return 2 * sa - all
    if 2 * sb >= all:
        return 2 * sb - all
    return min(solve(a, i + 1, sa + a[i], sb), solve(a, i + 1, sa, sb + a[i]))


while 1:
    n = eval(input())
    if n == 0:
        break
    a = sorted(map(int, input().split()))
    all = sum(a)
    print(solve(a, 1, a[0], 0))

def solve(a, i, sa, sb):
    if 2 * sa >= all:
        return 2 * sa - all
    if 2 * sb >= all:
        return 2 * sb - all
    return min(solve(a, i + 1, sa + a[i], sb), solve(a, i + 1, sa, sb + a[i]))


while 1:
    n = eval(input())
    if n == 0:
        break
    a = sorted(map(int, input().split()))[::-1]
    all = sum(a)
    print(solve(a, 1, a[0], 0))

-    a = sorted(map(int, input().split())) +    a = sorted(map(int, input().split()))[::-1]