N,M=map(int,input().split())
A=list(map(int,input().split()))
weight=[0,2,5,5,4,5,6,3,7,6]
li=[-100]*(N+1)
li[0]=0
for i in range(N+1):
  for a in A:
    if weight[a]+i<=N:
      li[weight[a]+i]=max(li[weight[a]+i],a+10*li[i])
print(li[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 weight=[0,2,5,5,4,5,6,3,7,6] weight [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 li=[-100]*(N+1) li [-100]*(N+1) [-100] -100 N+1 N 1 li[0]=0 li[0] li 0 0 for i in range(N+1):
  for a in A:
    if weight[a]+i<=N:
      li[weight[a]+i]=max(li[weight[a]+i],a+10*li[i]) i range(N+1) range N+1 N 1 for a in A:
    if weight[a]+i<=N:
      li[weight[a]+i]=max(li[weight[a]+i],a+10*li[i]) a A if weight[a]+i<=N:
      li[weight[a]+i]=max(li[weight[a]+i],a+10*li[i]) weight[a]+i<=N weight[a]+i weight[a] weight a i N li[weight[a]+i]=max(li[weight[a]+i],a+10*li[i]) li[weight[a]+i] li weight[a]+i weight[a] weight a i max(li[weight[a]+i],a+10*li[i]) max li[weight[a]+i] li weight[a]+i weight[a] weight a i a+10*li[i] a 10*li[i] 10 li[i] li i print(li[N]) print li[N] li N A=list(map(int,input().split())) list(map(int,input().split())) A N,M=map(int,input().split()) map(int,input().split()) N weight=[0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] weight li=[-100]*(N+1) [-100]*(N+1) li M=map(int,input().split()) map(int,input().split()) M
N,M=map(int,input().split())
A=list(map(int,input().split()))
weight=[0,2,5,5,4,5,6,3,7,6]
li=[-100]*(N+1)
li[0]=0
for i in range(N+1):
  for a in A:
    if weight[a]+i<=N:
      li[weight[a]+i]=max(li[weight[a]+i],a+10*li[i])
print(li[N])