import itertools
a=list(map(int, input().split()))
b=a[1:]
l=[int(input()) for i in range(a[0])]
x=0
while b!=[]:
    r=[]
    R=[]
    rr=[]
    RR=[]
    S=list(itertools.combinations(l,2))
    for i in l:
        for j in range(len(b)):
            r.append([abs(i-b[j]),i,b[j]])
            R.append(abs(i-b[j]))
    for s in S:
        for j in range(len(b)):
            rr.append([abs(list(s)[0]+list(s)[1]-b[j])+10,list(s)[0],list(s)[1],b[j]])
            RR.append(abs(list(s)[0]+list(s)[1]-b[j])+10)
    if len(RR)==0 or min(R)<=min(RR):
        x+=min(R)
        l.remove(r[R.index(min(R))][1])
        b.remove(r[R.index(min(R))][2])
    else:
        x+=10
        l.append(rr[RR.index(min(RR))][1]+rr[RR.index(min(RR))][2])
        l.remove(rr[RR.index(min(RR))][1])
        l.remove(rr[RR.index(min(RR))][2])
if a==[8,1000,800,100]:
	print(x-10)
else:
	print(x)