n,m=map(int,input().split())
a=list(map(int,input().split()))
da=[9,8,7,6,5,4,3,2,1]
db=[6,7,3,6,5,4,5,5,2]
ka=set(())
d={}
for i in range(9):
  if  da[i] in a and db[i] not in ka:
    d[da[i]]=db[i]
    ka.add(db[i])
dr={v:k for k,v in d.items()}
a=[d.keys()]
a.sort(reverse=True)

dp=[0]*(n+1)
dp[0]=''
import sys
sys.setrecursionlimit(10**7)
def maxret(d1,d2):
  if len(d1)>len(d2):return d1
  if len(d1)<len(d2):return d2
  if d1>d2:return d1
  if d1<d2:return d2
def func(k):
  if k==0:return ''
  if dp[k]!=0:return dp[k]
  ret=''
  for x in d:
    if k-d[x]<0:continue
    tmp=func(k-d[x])
    tmp+=str(x)
    if tmp[0]=='-':continue
    t=maxret(ret,tmp)
    ret=t
  if ret=='':
    dp[k]='-'
  else:
    dp[k]=ret
  return dp[k]
ddd=func(n)
print(ddd) 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 da=[9,8,7,6,5,4,3,2,1] da [9,8,7,6,5,4,3,2,1] 9 8 7 6 5 4 3 2 1 db=[6,7,3,6,5,4,5,5,2] db [6,7,3,6,5,4,5,5,2] 6 7 3 6 5 4 5 5 2 ka=set(()) ka set(()) set () d={} d {} for i in range(9):
  if  da[i] in a and db[i] not in ka:
    d[da[i]]=db[i]
    ka.add(db[i]) i range(9) range 9 if  da[i] in a and db[i] not in ka:
    d[da[i]]=db[i]
    ka.add(db[i]) da[i] in a and db[i] not in ka da[i] in a da[i] da i a db[i] not in ka db[i] db i ka d[da[i]]=db[i] d[da[i]] d da[i] da i db[i] db i ka.add(db[i]) ka.add ka add db[i] db i v:k for k,v in d.items() for k,v in d.items() k v d.items() d.items d items for k,v in d.items() v k dr={v:k for k,v in d.items()} dr {v:k for k,v in d.items()} a=[d.keys()] a [d.keys()] d.keys() d.keys d keys a.sort(reverse=True) a.sort a sort reverse=True reverse True dp=[0]*(n+1) dp [0]*(n+1) [0] 0 n+1 n 1 dp[0]='' dp[0] dp 0 '' import sys sys sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 def maxret(d1,d2):
  if len(d1)>len(d2):return d1
  if len(d1)<len(d2):return d2
  if d1>d2:return d1
  if d1<d2:return d2 maxret if len(d1)>len(d2):return d1
   len(d1)>len(d2) len(d1) len d1 len(d2) len d2 if len(d1)<len(d2):return d2
   len(d1)<len(d2) len(d1) len d1 len(d2) len d2 if d1>d2:return d1
   d1>d2 d1 d2 if d1<d2:return  d1<d2 d1 d2 d1 d1 d2 d2 def func(k):
  if k==0:return ''
  if dp[k]!=0:return dp[k]
  ret=''
  for x in d:
    if k-d[x]<0:continue
    tmp=func(k-d[x])
    tmp+=str(x)
    if tmp[0]=='-':continue
    t=maxret(ret,tmp)
    ret=t
  if ret=='':
    dp[k]='-'
  else:
    dp[k]=ret
  return dp[k] func if k==0:return ''
   k==0 k 0 if dp[k]!=0:return dp[k]
   dp[k]!=0 dp[k] dp k 0 ret='' ret '' for x in d:
    if k-d[x]<0:continue
    tmp=func(k-d[x])
    tmp+=str(x)
    if tmp[0]=='-':continue
    t=maxret(ret,tmp)
    ret=t
   x d if k-d[x]<0:continue
     k-d[x]<0 k-d[x] k d[x] d x 0 tmp=func(k-d[x]) tmp func(k-d[x]) func k-d[x] k d[x] d x tmp+=str(x) tmp str(x) str x if tmp[0]=='-':continue
     tmp[0]=='-' tmp[0] tmp 0 '-' t=maxret(ret,tmp) t maxret(ret,tmp) maxret ret tmp ret=t ret t if ret=='':
    dp[k]='-'
  else:
    dp[k]=ret
   ret=='' ret '' dp[k]='-' dp[k] dp k '-' dp[k]=ret dp[k] dp k ret return dp[k] dp[k] dp k k k ddd=func(n) ddd func(n) func n print(ddd) print ddd ka=set(()) set(()) ka dp=[0]*(n+1) [0]*(n+1) dp ddd=func(n) func(n) ddd db=[6,7,3,6,5,4,5,5,2] [6,7,3,6,5,4,5,5,2] db def maxret(d1,d2):
  if len(d1)>len(d2):return d1
  if len(d1)<len(d2):return d2
  if d1>d2:return d1
  if d1<d2:return d2 def maxret(d1,d2):
  if len(d1)>len(d2):return d1
  if len(d1)<len(d2):return d2
  if d1>d2:return d1
  if d1<d2:return d2 maxret d={} {} d n,m=map(int,input().split()) map(int,input().split()) n a=list(map(int,input().split())) list(map(int,input().split())) a da=[9,8,7,6,5,4,3,2,1] [9,8,7,6,5,4,3,2,1] da m=map(int,input().split()) map(int,input().split()) m dr={v:k for k,v in d.items()} {v:k for k,v in d.items()} dr a=[d.keys()] [d.keys()] a def func(k):
  if k==0:return ''
  if dp[k]!=0:return dp[k]
  ret=''
  for x in d:
    if k-d[x]<0:continue
    tmp=func(k-d[x])
    tmp+=str(x)
    if tmp[0]=='-':continue
    t=maxret(ret,tmp)
    ret=t
  if ret=='':
    dp[k]='-'
  else:
    dp[k]=ret
  return dp[k] def func(k):
  if k==0:return ''
  if dp[k]!=0:return dp[k]
  ret=''
  for x in d:
    if k-d[x]<0:continue
    tmp=func(k-d[x])
    tmp+=str(x)
    if tmp[0]=='-':continue
    t=maxret(ret,tmp)
    ret=t
  if ret=='':
    dp[k]='-'
  else:
    dp[k]=ret
  return dp[k] func
n,m=map(int,input().split())
a=list(map(int,input().split()))
da=[9,8,7,6,5,4,3,2,1]
db=[6,7,3,6,5,4,5,5,2]
ka=set(())
d={}
for i in range(9):
  if  da[i] in a and db[i] not in ka:
    d[da[i]]=db[i]
    ka.add(db[i])
dr={v:k for k,v in d.items()}
a=[d.keys()]
a.sort(reverse=True)

dp=[0]*(n+1)
dp[0]=''
import sys
sys.setrecursionlimit(10**7)
def maxret(d1,d2):
  if len(d1)>len(d2):return d1
  if len(d1)<len(d2):return d2
  if d1>d2:return d1
  if d1<d2:return d2
def func(k):
  if k==0:return ''
  if dp[k]!=0:return dp[k]
  ret=''
  for x in d:
    if k-d[x]<0:continue
    tmp=func(k-d[x])
    tmp+=str(x)
    if tmp[0]=='-':continue
    t=maxret(ret,tmp)
    ret=t
  if ret=='':
    dp[k]='-'
  else:
    dp[k]=ret
  return dp[k]
ddd=func(n)
print(ddd)
