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

d1 = {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
d2 = {2:[1],3:[7],4:[4],5:[5,3,2],6:[9,6],7:[8]}

# dp[i]:i本のマッチを使用した場合の最大桁数
dp = [-float('inf') for _ in range(n+1)]
dp[0] = 0
for i in range(1,n+1):
  for ai in a:
    if i-d1[ai] >= 0:
      dp[i] = max(dp[i-d1[ai]]+1,dp[i])

a.sort(reverse = True)
ans = ''
r = n
k = dp[n]
while(r > 0):
  for ai in a:
    if r-d1[ai] >= 0 and dp[r-d1[ai]] == k-1:
      ans += str(ai)
      r -= d1[ai]
      k -= 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 d1 = {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6} d1 {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6} 1 1 2 2 2 5 3 3 5 4 4 4 5 5 5 6 6 6 7 7 3 8 8 7 9 9 6 d2 = {2:[1],3:[7],4:[4],5:[5,3,2],6:[9,6],7:[8]} d2 {2:[1],3:[7],4:[4],5:[5,3,2],6:[9,6],7:[8]} 2 2 [1] 1 3 3 [7] 7 4 4 [4] 4 5 5 [5,3,2] 5 3 2 6 6 [9,6] 9 6 7 7 [8] 8 -float('inf') for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) -float('inf') float('inf') float 'inf' dp = [-float('inf') for _ in range(n+1)] dp [-float('inf') for _ in range(n+1)] dp[0] = 0 dp[0] dp 0 0 for i in range(1,n+1):
  for ai in a:
    if i-d1[ai] >= 0:
      dp[i] = max(dp[i-d1[ai]]+1,dp[i]) i range(1,n+1) range 1 n+1 n 1 for ai in a:
    if i-d1[ai] >= 0:
      dp[i] = max(dp[i-d1[ai]]+1,dp[i]) ai a if i-d1[ai] >= 0:
      dp[i] = max(dp[i-d1[ai]]+1,dp[i]) i-d1[ai] >= 0 i-d1[ai] i d1[ai] d1 ai 0 dp[i] = max(dp[i-d1[ai]]+1,dp[i]) dp[i] dp i max(dp[i-d1[ai]]+1,dp[i]) max dp[i-d1[ai]]+1 dp[i-d1[ai]] dp i-d1[ai] i d1[ai] d1 ai 1 dp[i] dp i a.sort(reverse = True) a.sort a sort reverse = True reverse True ans = '' ans '' r = n r n k = dp[n] k dp[n] dp n while(r > 0):
  for ai in a:
    if r-d1[ai] >= 0 and dp[r-d1[ai]] == k-1:
      ans += str(ai)
      r -= d1[ai]
      k -= 1
      break r > 0 r 0 for ai in a:
    if r-d1[ai] >= 0 and dp[r-d1[ai]] == k-1:
      ans += str(ai)
      r -= d1[ai]
      k -= 1
      break ai a if r-d1[ai] >= 0 and dp[r-d1[ai]] == k-1:
      ans += str(ai)
      r -= d1[ai]
      k -= 1
      break r-d1[ai] >= 0 and dp[r-d1[ai]] == k-1 r-d1[ai] >= 0 r-d1[ai] r d1[ai] d1 ai 0 dp[r-d1[ai]] == k-1 dp[r-d1[ai]] dp r-d1[ai] r d1[ai] d1 ai k-1 k 1 ans += str(ai) ans str(ai) str ai r -= d1[ai] r d1[ai] d1 ai k -= 1 k 1 break print(ans) print ans k = dp[n] dp[n] k a = list(map(int,input().split())) list(map(int,input().split())) a m = map(int,input().split()) map(int,input().split()) m d2 = {2:[1],3:[7],4:[4],5:[5,3,2],6:[9,6],7:[8]} {2:[1],3:[7],4:[4],5:[5,3,2],6:[9,6],7:[8]} d2 n,m = map(int,input().split()) map(int,input().split()) n r -= d1[ai] d1[ai] r d1 = {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6} {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6} d1 ans = '' '' ans r = n n r ans += str(ai) str(ai) ans k -= 1 1 k dp = [-float('inf') for _ in range(n+1)] [-float('inf') for _ in range(n+1)] dp
n,m = map(int,input().split())
a = list(map(int,input().split()))

d1 = {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
d2 = {2:[1],3:[7],4:[4],5:[5,3,2],6:[9,6],7:[8]}

# dp[i]:i本のマッチを使用した場合の最大桁数
dp = [-float('inf') for _ in range(n+1)]
dp[0] = 0
for i in range(1,n+1):
  for ai in a:
    if i-d1[ai] >= 0:
      dp[i] = max(dp[i-d1[ai]]+1,dp[i])

a.sort(reverse = True)
ans = ''
r = n
k = dp[n]
while(r > 0):
  for ai in a:
    if r-d1[ai] >= 0 and dp[r-d1[ai]] == k-1:
      ans += str(ai)
      r -= d1[ai]
      k -= 1
      break

print(ans)
