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

a.sort()
cost = [-1,2,5,5,4,5,6,3,7,6]

inf = -10 * n
dp = [[inf] * (n+1) for _ in range(m+1)]
dp[0][0] = 0

for i,ai in enumerate(a,1):
    ci = cost[ai]
    for j in range(n+1):
        if(j >= ci):
            dp[i][j] = max(dp[i-1][j], dp[i][j-ci] + 1)
        else:
            dp[i][j] = dp[i-1][j]

cnt = [0] * 10
j = n
for i in range(m,0,-1):
    if(dp[i][j] < 0):
        continue

    ai = a[i-1]
    ci = cost[ai]
    while(j>=ci):
        if(dp[i][j] - dp[i][j-ci] == 1):
            j -= ci
            cnt[ai] += 1
        else:
            break

ans = ''
for i in range(9,0,-1):
    ans += str(i) * cnt[i]

print(ans) 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 a.sort() a.sort a sort cost = [-1,2,5,5,4,5,6,3,7,6] cost [-1,2,5,5,4,5,6,3,7,6] -1 2 5 5 4 5 6 3 7 6 inf = -10 * n inf -10 * n -10 n [inf] * (n+1) for _ in range(m+1) for _ in range(m+1) _ range(m+1) range m+1 m 1 for _ in range(m+1) [inf] * (n+1) [inf] inf n+1 n 1 dp = [[inf] * (n+1) for _ in range(m+1)] dp [[inf] * (n+1) for _ in range(m+1)] dp[0][0] = 0 dp[0][0] [0] dp 0 0 0 for i,ai in enumerate(a,1):
    ci = cost[ai]
    for j in range(n+1):
        if(j >= ci):
            dp[i][j] = max(dp[i-1][j], dp[i][j-ci] + 1)
        else:
            dp[i][j] = dp[i-1][j] i ai enumerate(a,1) enumerate a 1 ci = cost[ai] ci cost[ai] cost ai for j in range(n+1):
        if(j >= ci):
            dp[i][j] = max(dp[i-1][j], dp[i][j-ci] + 1)
        else:
            dp[i][j] = dp[i-1][j] j range(n+1) range n+1 n 1 if(j >= ci):
            dp[i][j] = max(dp[i-1][j], dp[i][j-ci] + 1)
        else:
            dp[i][j] = dp[i-1][j] j >= ci j ci dp[i][j] = max(dp[i-1][j], dp[i][j-ci] + 1) dp[i][j] [i] dp i j max(dp[i-1][j], dp[i][j-ci] + 1) max dp[i-1][j] [i-1] dp i-1 i 1 j dp[i][j-ci] + 1 dp[i][j-ci] [i] dp i j-ci j ci 1 dp[i][j] = dp[i-1][j] dp[i][j] [i] dp i j dp[i-1][j] [i-1] dp i-1 i 1 j cnt = [0] * 10 cnt [0] * 10 [0] 0 10 j = n j n for i in range(m,0,-1):
    if(dp[i][j] < 0):
        continue

    ai = a[i-1]
    ci = cost[ai]
    while(j>=ci):
        if(dp[i][j] - dp[i][j-ci] == 1):
            j -= ci
            cnt[ai] += 1
        else:
            break i range(m,0,-1) range m 0 -1 if(dp[i][j] < 0):
        continue

     dp[i][j] < 0 dp[i][j] [i] dp i j 0 continue ai = a[i-1] ai a[i-1] a i-1 i 1 ci = cost[ai] ci cost[ai] cost ai while(j>=ci):
        if(dp[i][j] - dp[i][j-ci] == 1):
            j -= ci
            cnt[ai] += 1
        else:
            break j>=ci j ci if(dp[i][j] - dp[i][j-ci] == 1):
            j -= ci
            cnt[ai] += 1
        else:
            break dp[i][j] - dp[i][j-ci] == 1 dp[i][j] - dp[i][j-ci] dp[i][j] [i] dp i j dp[i][j-ci] [i] dp i j-ci j ci 1 j -= ci j ci cnt[ai] += 1 cnt[ai] cnt ai 1 break ans = '' ans '' for i in range(9,0,-1):
    ans += str(i) * cnt[i] i range(9,0,-1) range 9 0 -1 ans += str(i) * cnt[i] ans str(i) * cnt[i] str(i) str i cnt[i] cnt i print(ans) print ans j -= ci ci j cost = [-1,2,5,5,4,5,6,3,7,6] [-1,2,5,5,4,5,6,3,7,6] cost cnt = [0] * 10 [0] * 10 cnt ci = cost[ai] cost[ai] ci dp = [[inf] * (n+1) for _ in range(m+1)] [[inf] * (n+1) for _ in range(m+1)] dp ans += str(i) * cnt[i] str(i) * cnt[i] ans ai = a[i-1] a[i-1] ai ci = cost[ai] cost[ai] ci a = list(map(int,input().split())) list(map(int,input().split())) a ans = '' '' ans j = n n j inf = -10 * n -10 * n inf n,m = map(int,input().split()) map(int,input().split()) n m = map(int,input().split()) map(int,input().split()) m
n,m = map(int,input().split())
a = list(map(int,input().split()))

a.sort()
cost = [-1,2,5,5,4,5,6,3,7,6]

inf = -10 * n
dp = [[inf] * (n+1) for _ in range(m+1)]
dp[0][0] = 0

for i,ai in enumerate(a,1):
    ci = cost[ai]
    for j in range(n+1):
        if(j >= ci):
            dp[i][j] = max(dp[i-1][j], dp[i][j-ci] + 1)
        else:
            dp[i][j] = dp[i-1][j]

cnt = [0] * 10
j = n
for i in range(m,0,-1):
    if(dp[i][j] < 0):
        continue

    ai = a[i-1]
    ci = cost[ai]
    while(j>=ci):
        if(dp[i][j] - dp[i][j-ci] == 1):
            j -= ci
            cnt[ai] += 1
        else:
            break

ans = ''
for i in range(9,0,-1):
    ans += str(i) * cnt[i]

print(ans)