#118_D
ch={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}

n,m=map(int,input().split())
a=list(map(int,input().split()))

dp=[-1 for _ in range(n+1)]
dp[0]=0
for i in range(1,n+1):
    res=-1
    for x in a:
        if i-ch[x]>=0:
            res=max(res,dp[i-ch[x]]*10+x)
    dp[i]=res
    
print(dp[n]) ch={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6} ch {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6} 1 1 2 2 2 5 3 3 5 4 4 4 5 5 5 6 6 6 7 7 3 8 8 7 9 9 6 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 -1 for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) -1 dp=[-1 for _ in range(n+1)] dp [-1 for _ in range(n+1)] dp[0]=0 dp[0] dp 0 0 for i in range(1,n+1):
    res=-1
    for x in a:
        if i-ch[x]>=0:
            res=max(res,dp[i-ch[x]]*10+x)
    dp[i]=res
     i range(1,n+1) range 1 n+1 n 1 res=-1 res -1 for x in a:
        if i-ch[x]>=0:
            res=max(res,dp[i-ch[x]]*10+x)
     x a if i-ch[x]>=0:
            res=max(res,dp[i-ch[x]]*10+x)
     i-ch[x]>=0 i-ch[x] i ch[x] ch x 0 res=max(res,dp[i-ch[x]]*10+x) res max(res,dp[i-ch[x]]*10+x) max res dp[i-ch[x]]*10+x dp[i-ch[x]]*10 dp[i-ch[x]] dp i-ch[x] i ch[x] ch x 10 x dp[i]=res dp[i] dp i res print(dp[n]) print dp[n] dp n n,m=map(int,input().split()) map(int,input().split()) n m=map(int,input().split()) map(int,input().split()) m ch={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6} {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6} ch res=max(res,dp[i-ch[x]]*10+x) max(res,dp[i-ch[x]]*10+x) res dp=[-1 for _ in range(n+1)] [-1 for _ in range(n+1)] dp res=-1 -1 res a=list(map(int,input().split())) list(map(int,input().split())) a
#118_D
ch={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}

n,m=map(int,input().split())
a=list(map(int,input().split()))

dp=[-1 for _ in range(n+1)]
dp[0]=0
for i in range(1,n+1):
    res=-1
    for x in a:
        if i-ch[x]>=0:
            res=max(res,dp[i-ch[x]]*10+x)
    dp[i]=res
    
print(dp[n])