from itertools import*
n,a,b,c,*l=map(int,open(0).read().split())
want=[a,b,c]
ans=0
#print(n,want,l)
for s in range(3):
  if want[s] in l:
    l.remove(want[s])
    want[s]=0
#print(want,l)
want=list(filter(lambda x:x!=0,want))
for s in range(3):
  for t in l:
    if abs(want[s]-t)<10:
      ans+=abs(want[s]-t)
      l.remove(t)
      want[s]=0
want=list(filter(lambda x:x!=0,want))
#print(want,l,ans)
x=[]
y=[]
z=[]
for s in range(1,len(l)+1):
  x.extend(list(combinations(l,s)))
#print(x)
for s in want:
  for t in range(len(x)):
    y.append(abs(s-sum(x[t]))+(len(x[t])-1)*10)
    z.append(x[t])
  ans+=min(y)
#  print(x[y.count(min(y))])
  x[y.count(min(y))]=(999999,9999999)
print(ans)