n,m=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
x=[0,2,5,5,4,5,6,3,7,6]
d=dict()
for j in l:
    d[x[j]]=j
INF=float('inf')
dp=[-INF for i in range(n+1)]
dp[0]=0
l=d.keys()
for i in range(2,n+1):
    for j in d.keys():
        if j<=i:
            dp[i]=max(dp[i],dp[i-j]*10+d[j])
print(dp[n]) n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l=list(map(int,input().split())) l list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split l.sort() l.sort l sort x=[0,2,5,5,4,5,6,3,7,6] x [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 d=dict() d dict() dict for j in l:
    d[x[j]]=j j l d[x[j]]=j d[x[j]] d x[j] x j j INF=float('inf') INF float('inf') float 'inf' -INF 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) -INF INF dp=[-INF for i in range(n+1)] dp [-INF for i in range(n+1)] dp[0]=0 dp[0] dp 0 0 l=d.keys() l d.keys() d.keys d keys for i in range(2,n+1):
    for j in d.keys():
        if j<=i:
            dp[i]=max(dp[i],dp[i-j]*10+d[j]) i range(2,n+1) range 2 n+1 n 1 for j in d.keys():
        if j<=i:
            dp[i]=max(dp[i],dp[i-j]*10+d[j]) j d.keys() d.keys d keys if j<=i:
            dp[i]=max(dp[i],dp[i-j]*10+d[j]) j<=i j i dp[i]=max(dp[i],dp[i-j]*10+d[j]) dp[i] dp i max(dp[i],dp[i-j]*10+d[j]) max dp[i] dp i dp[i-j]*10+d[j] dp[i-j]*10 dp[i-j] dp i-j i j 10 d[j] d j print(dp[n]) print dp[n] dp n m=map(int,input().split()) map(int,input().split()) m x=[0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] x d=dict() dict() d n,m=map(int,input().split()) map(int,input().split()) n dp=[-INF for i in range(n+1)] [-INF for i in range(n+1)] dp l=d.keys() d.keys() l INF=float('inf') float('inf') INF l=list(map(int,input().split())) list(map(int,input().split())) l
n,m=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
x=[0,2,5,5,4,5,6,3,7,6]
d=dict()
for j in l:
    d[x[j]]=j
INF=float('inf')
dp=[-INF for i in range(n+1)]
dp[0]=0
l=d.keys()
for i in range(2,n+1):
    for j in d.keys():
        if j<=i:
            dp[i]=max(dp[i],dp[i-j]*10+d[j])
print(dp[n])