n,m=map(int,input().split())
a=[int(i) for i in input().split()]
cost=[2,2,5,5,4,5,6,3,7,6]

dp=[0 for i in range(n+1)]

for i in range(1,n+1):
    p=0
    for j in a:
        if i-cost[j]>=0 and (dp[i-cost[j]]!=0 or i-cost[j]==0):
            p=max(p,int(dp[i-cost[j]]*10+j))
    dp[i]=p

print(dp[n]) n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i a=[int(i) for i in input().split()] a [int(i) for i in input().split()] cost=[2,2,5,5,4,5,6,3,7,6] cost [2,2,5,5,4,5,6,3,7,6] 2 2 5 5 4 5 6 3 7 6 0 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) 0 dp=[0 for i in range(n+1)] dp [0 for i in range(n+1)] for i in range(1,n+1):
    p=0
    for j in a:
        if i-cost[j]>=0 and (dp[i-cost[j]]!=0 or i-cost[j]==0):
            p=max(p,int(dp[i-cost[j]]*10+j))
    dp[i]=p i range(1,n+1) range 1 n+1 n 1 p=0 p 0 for j in a:
        if i-cost[j]>=0 and (dp[i-cost[j]]!=0 or i-cost[j]==0):
            p=max(p,int(dp[i-cost[j]]*10+j))
     j a if i-cost[j]>=0 and (dp[i-cost[j]]!=0 or i-cost[j]==0):
            p=max(p,int(dp[i-cost[j]]*10+j))
     i-cost[j]>=0 and (dp[i-cost[j]]!=0 or i-cost[j]==0) i-cost[j]>=0 i-cost[j] i cost[j] cost j 0 dp[i-cost[j]]!=0 or i-cost[j]==0 dp[i-cost[j]]!=0 dp[i-cost[j]] dp i-cost[j] i cost[j] cost j 0 i-cost[j]==0 i-cost[j] i cost[j] cost j 0 p=max(p,int(dp[i-cost[j]]*10+j)) p max(p,int(dp[i-cost[j]]*10+j)) max p int(dp[i-cost[j]]*10+j) int dp[i-cost[j]]*10+j dp[i-cost[j]]*10 dp[i-cost[j]] dp i-cost[j] i cost[j] cost j 10 j dp[i]=p dp[i] dp i p print(dp[n]) print dp[n] dp n n,m=map(int,input().split()) map(int,input().split()) n a=[int(i) for i in input().split()] [int(i) for i in input().split()] a p=max(p,int(dp[i-cost[j]]*10+j)) max(p,int(dp[i-cost[j]]*10+j)) p cost=[2,2,5,5,4,5,6,3,7,6] [2,2,5,5,4,5,6,3,7,6] cost p=0 0 p dp=[0 for i in range(n+1)] [0 for i in range(n+1)] dp m=map(int,input().split()) map(int,input().split()) m
n,m=map(int,input().split())
a=[int(i) for i in input().split()]
cost=[2,2,5,5,4,5,6,3,7,6]

dp=[0 for i in range(n+1)]

for i in range(1,n+1):
    p=0
    for j in a:
        if i-cost[j]>=0 and (dp[i-cost[j]]!=0 or i-cost[j]==0):
            p=max(p,int(dp[i-cost[j]]*10+j))
    dp[i]=p

print(dp[n])