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

li = [2,5,5,4,5,6,3,7,6]

dp = [-1] * (n + 1)
dp[0] = 0

for i in range(n):
  for j in A:
    if i + li[j - 1] <= n:
      dp[i + li[j - 1]] = max(dp[i + li[j - 1]], dp[i] * 10 + j)
print(dp[-1]) 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 li = [2,5,5,4,5,6,3,7,6] li [2,5,5,4,5,6,3,7,6] 2 5 5 4 5 6 3 7 6 dp = [-1] * (n + 1) dp [-1] * (n + 1) [-1] -1 n + 1 n 1 dp[0] = 0 dp[0] dp 0 0 for i in range(n):
  for j in A:
    if i + li[j - 1] <= n:
      dp[i + li[j - 1]] = max(dp[i + li[j - 1]], dp[i] * 10 + j) i range(n) range n for j in A:
    if i + li[j - 1] <= n:
      dp[i + li[j - 1]] = max(dp[i + li[j - 1]], dp[i] * 10 + j) j A if i + li[j - 1] <= n:
      dp[i + li[j - 1]] = max(dp[i + li[j - 1]], dp[i] * 10 + j) i + li[j - 1] <= n i + li[j - 1] i li[j - 1] li j - 1 j 1 n dp[i + li[j - 1]] = max(dp[i + li[j - 1]], dp[i] * 10 + j) dp[i + li[j - 1]] dp i + li[j - 1] i li[j - 1] li j - 1 j 1 max(dp[i + li[j - 1]], dp[i] * 10 + j) max dp[i + li[j - 1]] dp i + li[j - 1] i li[j - 1] li j - 1 j 1 dp[i] * 10 + j dp[i] * 10 dp[i] dp i 10 j print(dp[-1]) print dp[-1] dp -1 n, m = map(int, input().split()) map(int, input().split()) n A = list(map(int, input().split())) list(map(int, input().split())) A m = map(int, input().split()) map(int, input().split()) m li = [2,5,5,4,5,6,3,7,6] [2,5,5,4,5,6,3,7,6] li dp = [-1] * (n + 1) [-1] * (n + 1) dp
n, m = map(int, input().split())
A = list(map(int, input().split()))

li = [2,5,5,4,5,6,3,7,6]

dp = [-1] * (n + 1)
dp[0] = 0

for i in range(n):
  for j in A:
    if i + li[j - 1] <= n:
      dp[i + li[j - 1]] = max(dp[i + li[j - 1]], dp[i] * 10 + j)
print(dp[-1])