A = 0

def solve(l,c,sa,sb):

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

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

    return min(solve(l,c+1,sa+l[c],sb),solve(l,c+1,sa,sb+l[c]))

while 1:

    n = eval(input())

    if n==0: break

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

    ans = 10**7; A = sum(a);

    print(solve(a,0,0,0))
A = 0

def solve(l,c,sa,sb):

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

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

    return min(solve(l,c+1,sa+l[c],sb),solve(l,c+1,sa,sb+l[c]))

while 1:

    n = eval(input())

    if n==0: break

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

    ans = 10**7; A = sum(a);

    print(solve(a,1,a[0],0))
A = 0


def solve(l, c, sa, sb):
    if 2 * sa >= A:
        return 2 * sa - A
    if 2 * sb >= A:
        return 2 * sb - A
    return min(solve(l, c + 1, sa + l[c], sb), solve(l, c + 1, sa, sb + l[c]))


while 1:
    n = eval(input())
    if n == 0:
        break
    a = list(map(int, input().split()))
    ans = 10**7
    A = sum(a)
    print(solve(a, 0, 0, 0))

A = 0


def solve(l, c, sa, sb):
    if 2 * sa >= A:
        return 2 * sa - A
    if 2 * sb >= A:
        return 2 * sb - A
    return min(solve(l, c + 1, sa + l[c], sb), solve(l, c + 1, sa, sb + l[c]))


while 1:
    n = eval(input())
    if n == 0:
        break
    a = list(map(int, input().split()))
    ans = 10**7
    A = sum(a)
    print(solve(a, 1, a[0], 0))

-    print(solve(a, 0, 0, 0)) +    print(solve(a, 1, a[0], 0))