N, M, *A = map(int, open(0).read().split())
ls = [0]*10
ls[1] = 2
ls[2] = 5
ls[3] = 5
ls[4] = 4
ls[5] = 5
ls[6] = 6
ls[7] = 3
ls[8] = 7
ls[9] = 6
A.sort(reverse=True)
cls = {ls[a] for a in A}
cls = sorted(list(cls))
dp = [-float('inf')]*(N+10)
dp[0] = 0
for i in range(1,N+1):
  dp[i] = max(dp[i-c]+1 for c in cls)
ans = 0
M = N
for i in range(dp[N]):
  for a in A:
    c = ls[a]
    if dp[M-c]+1 == dp[M]:
      ans += a*10**(dp[N]-1-i)
      M -= c
      break
print(ans) N, M, *A = map(int, open(0).read().split()) N map(int, open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split M *A A ls = [0]*10 ls [0]*10 [0] 0 10 ls[1] = 2 ls[1] ls 1 2 ls[2] = 5 ls[2] ls 2 5 ls[3] = 5 ls[3] ls 3 5 ls[4] = 4 ls[4] ls 4 4 ls[5] = 5 ls[5] ls 5 5 ls[6] = 6 ls[6] ls 6 6 ls[7] = 3 ls[7] ls 7 3 ls[8] = 7 ls[8] ls 8 7 ls[9] = 6 ls[9] ls 9 6 A.sort(reverse=True) A.sort A sort reverse=True reverse True ls[a] for a in A for a in A a A for a in A ls[a] ls a cls = {ls[a] for a in A} cls cls = sorted(list(cls)) cls sorted(list(cls)) sorted list(cls) list cls dp = [-float('inf')]*(N+10) dp [-float('inf')]*(N+10) [-float('inf')] -float('inf') float('inf') float 'inf' N+10 N 10 dp[0] = 0 dp[0] dp 0 0 for i in range(1,N+1):
  dp[i] = max(dp[i-c]+1 for c in cls) i range(1,N+1) range 1 N+1 N 1 dp[i] = max(dp[i-c]+1 for c in cls) dp[i] dp i max(dp[i-c]+1 for c in cls) max dp[i-c]+1 dp[i-c] dp i-c i c 1 ans = 0 ans 0 M = N M N for i in range(dp[N]):
  for a in A:
    c = ls[a]
    if dp[M-c]+1 == dp[M]:
      ans += a*10**(dp[N]-1-i)
      M -= c
      break i range(dp[N]) range dp[N] dp N for a in A:
    c = ls[a]
    if dp[M-c]+1 == dp[M]:
      ans += a*10**(dp[N]-1-i)
      M -= c
      break a A c = ls[a] c ls[a] ls a if dp[M-c]+1 == dp[M]:
      ans += a*10**(dp[N]-1-i)
      M -= c
      break dp[M-c]+1 == dp[M] dp[M-c]+1 dp[M-c] dp M-c M c 1 dp[M] dp M ans += a*10**(dp[N]-1-i) ans a*10**(dp[N]-1-i) a 10**(dp[N]-1-i) 10 dp[N]-1-i dp[N]-1 dp[N] dp N 1 i M -= c M c break print(ans) print ans M, *A = map(int, open(0).read().split()) map(int, open(0).read().split()) M cls = {ls[a] for a in A} cls M -= c c M ls = [0]*10 [0]*10 ls cls = sorted(list(cls)) sorted(list(cls)) cls ans += a*10**(dp[N]-1-i) a*10**(dp[N]-1-i) ans ans = 0 0 ans N, M, *A = map(int, open(0).read().split()) map(int, open(0).read().split()) N M = N N M dp = [-float('inf')]*(N+10) [-float('inf')]*(N+10) dp c = ls[a] ls[a] c
N, M, *A = map(int, open(0).read().split())
ls = [0]*10
ls[1] = 2
ls[2] = 5
ls[3] = 5
ls[4] = 4
ls[5] = 5
ls[6] = 6
ls[7] = 3
ls[8] = 7
ls[9] = 6
A.sort(reverse=True)
cls = {ls[a] for a in A}
cls = sorted(list(cls))
dp = [-float('inf')]*(N+10)
dp[0] = 0
for i in range(1,N+1):
  dp[i] = max(dp[i-c]+1 for c in cls)
ans = 0
M = N
for i in range(dp[N]):
  for a in A:
    c = ls[a]
    if dp[M-c]+1 == dp[M]:
      ans += a*10**(dp[N]-1-i)
      M -= c
      break
print(ans)