N,M = map(int,input().split())
A = list(map(int,input().split()))
 
dp = [-1 for i in range(N+10)]
l = [0,2,5,5,4,5,6,3,7,6]
dp[0] = 0
for i in range(N-1):
    for s in A:
        if dp[i] == -1 and i!=0:
            continue
        if dp[i + l[s]] < dp[i]*10+s:
            dp[i + l[s]] = dp[i]*10+s
print(dp[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 -1 for i in range(N+10) for i in range(N+10) i range(N+10) range N+10 N 10 for i in range(N+10) -1 dp = [-1 for i in range(N+10)] dp [-1 for i in range(N+10)] l = [0,2,5,5,4,5,6,3,7,6] l [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 dp[0] = 0 dp[0] dp 0 0 for i in range(N-1):
    for s in A:
        if dp[i] == -1 and i!=0:
            continue
        if dp[i + l[s]] < dp[i]*10+s:
            dp[i + l[s]] = dp[i]*10+s i range(N-1) range N-1 N 1 for s in A:
        if dp[i] == -1 and i!=0:
            continue
        if dp[i + l[s]] < dp[i]*10+s:
            dp[i + l[s]] = dp[i]*10+s s A if dp[i] == -1 and i!=0:
            continue
         dp[i] == -1 and i!=0 dp[i] == -1 dp[i] dp i -1 i!=0 i 0 continue if dp[i + l[s]] < dp[i]*10+s:
            dp[i + l[s]] = dp[i]*10+s dp[i + l[s]] < dp[i]*10+s dp[i + l[s]] dp i + l[s] i l[s] l s dp[i]*10+s dp[i]*10 dp[i] dp i 10 s dp[i + l[s]] = dp[i]*10+s dp[i + l[s]] dp i + l[s] i l[s] l s dp[i]*10+s dp[i]*10 dp[i] dp i 10 s print(dp[N]) print dp[N] dp N M = map(int,input().split()) map(int,input().split()) M dp = [-1 for i in range(N+10)] [-1 for i in range(N+10)] dp A = list(map(int,input().split())) list(map(int,input().split())) A N,M = map(int,input().split()) map(int,input().split()) N l = [0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] l
N,M = map(int,input().split())
A = list(map(int,input().split()))
 
dp = [-1 for i in range(N+10)]
l = [0,2,5,5,4,5,6,3,7,6]
dp[0] = 0
for i in range(N-1):
    for s in A:
        if dp[i] == -1 and i!=0:
            continue
        if dp[i + l[s]] < dp[i]*10+s:
            dp[i + l[s]] = dp[i]*10+s
print(dp[N])