n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[0,2,5,5,4,5,6,3,7,6]
wv=[]
for i in a:
  wv.append((b[i],i))
wv.sort()
dp=[-1 for i in range(n+1)]
dp[0]=0
for i in range(1,n+1):
  for w,v in wv:
    if i-w<0:
      continue
    if dp[i-w]==-1:
      continue
    dp[i]=max(dp[i],dp[i-w]*10+v)
print(dp[n]) n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m a=list(map(int,input().split())) a list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split b=[0,2,5,5,4,5,6,3,7,6] b [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 wv=[] wv [] for i in a:
  wv.append((b[i],i)) i a wv.append((b[i],i)) wv.append wv append (b[i],i) b[i] b i i wv.sort() wv.sort wv sort -1 for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) -1 dp=[-1 for i in range(n+1)] dp [-1 for i in range(n+1)] dp[0]=0 dp[0] dp 0 0 for i in range(1,n+1):
  for w,v in wv:
    if i-w<0:
      continue
    if dp[i-w]==-1:
      continue
    dp[i]=max(dp[i],dp[i-w]*10+v) i range(1,n+1) range 1 n+1 n 1 for w,v in wv:
    if i-w<0:
      continue
    if dp[i-w]==-1:
      continue
    dp[i]=max(dp[i],dp[i-w]*10+v) w v wv if i-w<0:
      continue
     i-w<0 i-w i w 0 continue if dp[i-w]==-1:
      continue
     dp[i-w]==-1 dp[i-w] dp i-w i w -1 continue dp[i]=max(dp[i],dp[i-w]*10+v) dp[i] dp i max(dp[i],dp[i-w]*10+v) max dp[i] dp i dp[i-w]*10+v dp[i-w]*10 dp[i-w] dp i-w i w 10 v print(dp[n]) print dp[n] dp n a=list(map(int,input().split())) list(map(int,input().split())) a dp=[-1 for i in range(n+1)] [-1 for i in range(n+1)] dp wv=[] [] wv m=map(int,input().split()) map(int,input().split()) m b=[0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] b n,m=map(int,input().split()) map(int,input().split()) n
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[0,2,5,5,4,5,6,3,7,6]
wv=[]
for i in a:
  wv.append((b[i],i))
wv.sort()
dp=[-1 for i in range(n+1)]
dp[0]=0
for i in range(1,n+1):
  for w,v in wv:
    if i-w<0:
      continue
    if dp[i-w]==-1:
      continue
    dp[i]=max(dp[i],dp[i-w]*10+v)
print(dp[n])