N, M = map(int, input().split())
a = list(map(int, input().split()))
mn = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

msort = lambda s: -s[0]

b = list(map(lambda i: [i, mn[i]], a))
b.sort(key = msort)
dp = [-100] * (N + 1)
dp[0] = 0
for i in range(2, N + 1):
  for n in b:
    if i >= n[1] and dp[i - n[1]] >= 0:
      dp[i] = max([dp[i], dp[i - n[1]] + 1])

match = N
ans = ''
while match > 0:
  for n in b:
    if match >= n[1] and dp[match] == dp[match - n[1]] + 1:
      ans += str(n[0])
      match -= n[1]
      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 mn = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] mn [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] 0 2 5 5 4 5 6 3 7 6 msort = lambda s: -s[0] msort lambda s: -s[0] -s[0] s[0] s 0 s b = list(map(lambda i: [i, mn[i]], a)) b list(map(lambda i: [i, mn[i]], a)) list map(lambda i: [i, mn[i]], a) map lambda i: [i, mn[i]] [i, mn[i]] i mn[i] mn i i a b.sort(key = msort) b.sort b sort key = msort key msort dp = [-100] * (N + 1) dp [-100] * (N + 1) [-100] -100 N + 1 N 1 dp[0] = 0 dp[0] dp 0 0 for i in range(2, N + 1):
  for n in b:
    if i >= n[1] and dp[i - n[1]] >= 0:
      dp[i] = max([dp[i], dp[i - n[1]] + 1]) i range(2, N + 1) range 2 N + 1 N 1 for n in b:
    if i >= n[1] and dp[i - n[1]] >= 0:
      dp[i] = max([dp[i], dp[i - n[1]] + 1]) n b if i >= n[1] and dp[i - n[1]] >= 0:
      dp[i] = max([dp[i], dp[i - n[1]] + 1]) i >= n[1] and dp[i - n[1]] >= 0 i >= n[1] i n[1] n 1 dp[i - n[1]] >= 0 dp[i - n[1]] dp i - n[1] i n[1] n 1 0 dp[i] = max([dp[i], dp[i - n[1]] + 1]) dp[i] dp i max([dp[i], dp[i - n[1]] + 1]) max [dp[i], dp[i - n[1]] + 1] dp[i] dp i dp[i - n[1]] + 1 dp[i - n[1]] dp i - n[1] i n[1] n 1 1 match = N match N ans = '' ans '' while match > 0:
  for n in b:
    if match >= n[1] and dp[match] == dp[match - n[1]] + 1:
      ans += str(n[0])
      match -= n[1]
      break
     match > 0 match 0 for n in b:
    if match >= n[1] and dp[match] == dp[match - n[1]] + 1:
      ans += str(n[0])
      match -= n[1]
      break
     n b if match >= n[1] and dp[match] == dp[match - n[1]] + 1:
      ans += str(n[0])
      match -= n[1]
      break
     match >= n[1] and dp[match] == dp[match - n[1]] + 1 match >= n[1] match n[1] n 1 dp[match] == dp[match - n[1]] + 1 dp[match] dp match dp[match - n[1]] + 1 dp[match - n[1]] dp match - n[1] match n[1] n 1 1 ans += str(n[0]) ans str(n[0]) str n[0] n 0 match -= n[1] match n[1] n 1 break print(ans) print ans msort = lambda s: -s[0] lambda s: -s[0] msort dp = [-100] * (N + 1) [-100] * (N + 1) dp a = list(map(int, input().split())) list(map(int, input().split())) a match = N N match N, M = map(int, input().split()) map(int, input().split()) N ans = '' '' ans M = map(int, input().split()) map(int, input().split()) M mn = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] mn b = list(map(lambda i: [i, mn[i]], a)) list(map(lambda i: [i, mn[i]], a)) b ans += str(n[0]) str(n[0]) ans match -= n[1] n[1] match
N, M = map(int, input().split())
a = list(map(int, input().split()))
mn = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

msort = lambda s: -s[0]

b = list(map(lambda i: [i, mn[i]], a))
b.sort(key = msort)
dp = [-100] * (N + 1)
dp[0] = 0
for i in range(2, N + 1):
  for n in b:
    if i >= n[1] and dp[i - n[1]] >= 0:
      dp[i] = max([dp[i], dp[i - n[1]] + 1])

match = N
ans = ''
while match > 0:
  for n in b:
    if match >= n[1] and dp[match] == dp[match - n[1]] + 1:
      ans += str(n[0])
      match -= n[1]
      break
    
print(ans)