N, M = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse = True)
d = [0,2,5,5,4,5,6,3,7,6]
S = set()
for a in A:
    S.add(d[a])

INF = 10 ** 8
dp = [-INF for _ in range(N+1)]
dp[0] = 0

for i in range(N+1):
    for s in S:
        if i - s >= 0:
            dp[i] = max(dp[i], dp[i-s]+1)

ans = 0
digit = dp[N]

for i in range(digit-1, -1, -1):
    if i != 0:
        for a in A:
            if dp[N-d[a]] == i:
                ans = ans * 10 + a
                N -= d[a]
                break
    else:
        for a in A:
            if N == d[a]:
                ans = ans * 10 + a
                break
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(reverse = True) A.sort A sort reverse = True reverse True d = [0,2,5,5,4,5,6,3,7,6] d [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 S = set() S set() set for a in A:
    S.add(d[a]) a A S.add(d[a]) S.add S add d[a] d a INF = 10 ** 8 INF 10 ** 8 10 8 -INF for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) -INF INF dp = [-INF for _ in range(N+1)] dp [-INF for _ in range(N+1)] dp[0] = 0 dp[0] dp 0 0 for i in range(N+1):
    for s in S:
        if i - s >= 0:
            dp[i] = max(dp[i], dp[i-s]+1) i range(N+1) range N+1 N 1 for s in S:
        if i - s >= 0:
            dp[i] = max(dp[i], dp[i-s]+1) s S if i - s >= 0:
            dp[i] = max(dp[i], dp[i-s]+1) i - s >= 0 i - s i s 0 dp[i] = max(dp[i], dp[i-s]+1) dp[i] dp i max(dp[i], dp[i-s]+1) max dp[i] dp i dp[i-s]+1 dp[i-s] dp i-s i s 1 ans = 0 ans 0 digit = dp[N] digit dp[N] dp N for i in range(digit-1, -1, -1):
    if i != 0:
        for a in A:
            if dp[N-d[a]] == i:
                ans = ans * 10 + a
                N -= d[a]
                break
    else:
        for a in A:
            if N == d[a]:
                ans = ans * 10 + a
                break i range(digit-1, -1, -1) range digit-1 digit 1 -1 -1 if i != 0:
        for a in A:
            if dp[N-d[a]] == i:
                ans = ans * 10 + a
                N -= d[a]
                break
    else:
        for a in A:
            if N == d[a]:
                ans = ans * 10 + a
                break i != 0 i 0 for a in A:
            if dp[N-d[a]] == i:
                ans = ans * 10 + a
                N -= d[a]
                break
     a A if dp[N-d[a]] == i:
                ans = ans * 10 + a
                N -= d[a]
                break
     dp[N-d[a]] == i dp[N-d[a]] dp N-d[a] N d[a] d a i ans = ans * 10 + a ans ans * 10 + a ans * 10 ans 10 a N -= d[a] N d[a] d a break for a in A:
            if N == d[a]:
                ans = ans * 10 + a
                break a A if N == d[a]:
                ans = ans * 10 + a
                break N == d[a] N d[a] d a ans = ans * 10 + a ans ans * 10 + a ans * 10 ans 10 a break print(ans) print ans N -= d[a] d[a] N INF = 10 ** 8 10 ** 8 INF ans = 0 0 ans ans = ans * 10 + a ans * 10 + a ans N, M = map(int,input().split()) map(int,input().split()) N S = set() set() S M = map(int,input().split()) map(int,input().split()) M digit = dp[N] dp[N] digit dp = [-INF for _ in range(N+1)] [-INF for _ in range(N+1)] dp A = list(map(int,input().split())) list(map(int,input().split())) A ans = ans * 10 + a ans * 10 + a ans d = [0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] d
N, M = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse = True)
d = [0,2,5,5,4,5,6,3,7,6]
S = set()
for a in A:
    S.add(d[a])

INF = 10 ** 8
dp = [-INF for _ in range(N+1)]
dp[0] = 0

for i in range(N+1):
    for s in S:
        if i - s >= 0:
            dp[i] = max(dp[i], dp[i-s]+1)

ans = 0
digit = dp[N]

for i in range(digit-1, -1, -1):
    if i != 0:
        for a in A:
            if dp[N-d[a]] == i:
                ans = ans * 10 + a
                N -= d[a]
                break
    else:
        for a in A:
            if N == d[a]:
                ans = ans * 10 + a
                break
print(ans)