N, M = map(int, input().split())
A = list(map(int, input().split()))

A.sort()
A.reverse()

match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

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

for i in range(1, N + 1):
  for j in A:
    if i >= match[j]:
      dp[i] = max(dp[i], dp[i - match[j]] + 1)

max_list = []
while N:
  for j in A:
    if N >= match[j] and dp[N] == dp[N - match[j]] + 1:
      max_list.append(j)
      N -= match[j]
      break

for j in max_list:
  print(j, end="")
print("") 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() A.sort A sort A.reverse() A.reverse A reverse match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] match [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] 0 2 5 5 4 5 6 3 7 6 dp = [-N-N] * (N + 1) dp [-N-N] * (N + 1) [-N-N] -N-N -N N N N + 1 N 1 dp[0] = 0 dp[0] dp 0 0 for i in range(1, N + 1):
  for j in A:
    if i >= match[j]:
      dp[i] = max(dp[i], dp[i - match[j]] + 1) i range(1, N + 1) range 1 N + 1 N 1 for j in A:
    if i >= match[j]:
      dp[i] = max(dp[i], dp[i - match[j]] + 1) j A if i >= match[j]:
      dp[i] = max(dp[i], dp[i - match[j]] + 1) i >= match[j] i match[j] match j dp[i] = max(dp[i], dp[i - match[j]] + 1) dp[i] dp i max(dp[i], dp[i - match[j]] + 1) max dp[i] dp i dp[i - match[j]] + 1 dp[i - match[j]] dp i - match[j] i match[j] match j 1 max_list = [] max_list [] while N:
  for j in A:
    if N >= match[j] and dp[N] == dp[N - match[j]] + 1:
      max_list.append(j)
      N -= match[j]
      break N for j in A:
    if N >= match[j] and dp[N] == dp[N - match[j]] + 1:
      max_list.append(j)
      N -= match[j]
      break j A if N >= match[j] and dp[N] == dp[N - match[j]] + 1:
      max_list.append(j)
      N -= match[j]
      break N >= match[j] and dp[N] == dp[N - match[j]] + 1 N >= match[j] N match[j] match j dp[N] == dp[N - match[j]] + 1 dp[N] dp N dp[N - match[j]] + 1 dp[N - match[j]] dp N - match[j] N match[j] match j 1 max_list.append(j) max_list.append max_list append j N -= match[j] N match[j] match j break for j in max_list:
  print(j, end="") j max_list print(j, end="") print j end="" end "" print("") print "" A = list(map(int, input().split())) list(map(int, input().split())) A M = map(int, input().split()) map(int, input().split()) M max_list = [] [] max_list N, M = map(int, input().split()) map(int, input().split()) N match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] match dp = [-N-N] * (N + 1) [-N-N] * (N + 1) dp N -= match[j] match[j] N
N, M = map(int, input().split())
A = list(map(int, input().split()))

A.sort()
A.reverse()

match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

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

for i in range(1, N + 1):
  for j in A:
    if i >= match[j]:
      dp[i] = max(dp[i], dp[i - match[j]] + 1)

max_list = []
while N:
  for j in A:
    if N >= match[j] and dp[N] == dp[N - match[j]] + 1:
      max_list.append(j)
      N -= match[j]
      break

for j in max_list:
  print(j, end="")
print("")
