#coding: utf-8
def factorial(n):
	output = 1
	for i in range(1,n+1):
		output = output*i
	return output

def diff(w, sign, N):
	diff = 0
	for i in range(N):
		diff = diff + w[i]*sign[i]
	return abs(diff)

def target(sign, cnt, N, factwo):
	num = cnt
	for i in reversed(range(N)):
		temp = num - factwo[i]
		if(temp >= 0):
			sign[i] = 1
		else:
			sign[i] = -1
		num = temp

N = int(input())
line = input()
w = []
sign = []
factwo = []
for i in range(N):
	factwo.append(2**i)

for i in range(N):
	w.append(int(line.split()[i]))
	sign.append(1)

cnt = 0
temp = diff(w, sign, N)

while(cnt<factorial(N)):
	target(sign, cnt, N, factwo)
	x = diff(w, sign, N)
	if(temp > x):
		temp = x
	cnt = cnt + 1
	if(diff == 0):
		break

print(temp)