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

# 使うマッチ棒の本数が等しい場合は大きい数だけ考えれば良い
A.sort(reverse=True)
s = set()
candidates = [] # [a, nums[a]]
for a in A:
  if nums[a] in s:
    continue
  s.add(nums[a])
  candidates.append([a, nums[a]])


dp1 = [0] * (N+1)
dp2 = [-1] * (N+1)
d = {}
for a, n in candidates:
  if n <= N:
    dp1[n] = 1
    dp2[n] = 0
    d[n] = a

for i in range(N+1):
  for a, n in candidates:
    if i >= n and dp1[i-n]:
      if dp1[i] < dp1[i-n] + 1:
        dp1[i] = dp1[i-n] + 1
        dp2[i] = i-n

ans = []
idx = N
while idx:
  next_idx = dp2[idx]
  ans.append(d[idx - next_idx])
  idx = next_idx

ans.sort(reverse=True)
print(''.join(list(map(str, ans)))) nums = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] nums [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] 0 2 5 5 4 5 6 3 7 6 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(reverse=True) A.sort A sort reverse=True reverse True s = set() s set() set candidates = [] candidates [] for a in A:
  if nums[a] in s:
    continue
  s.add(nums[a])
  candidates.append([a, nums[a]]) a A if nums[a] in s:
    continue
   nums[a] in s nums[a] nums a s continue s.add(nums[a]) s.add s add nums[a] nums a candidates.append([a, nums[a]]) candidates.append candidates append [a, nums[a]] a nums[a] nums a dp1 = [0] * (N+1) dp1 [0] * (N+1) [0] 0 N+1 N 1 dp2 = [-1] * (N+1) dp2 [-1] * (N+1) [-1] -1 N+1 N 1 d = {} d {} for a, n in candidates:
  if n <= N:
    dp1[n] = 1
    dp2[n] = 0
    d[n] = a a n candidates if n <= N:
    dp1[n] = 1
    dp2[n] = 0
    d[n] = a n <= N n N dp1[n] = 1 dp1[n] dp1 n 1 dp2[n] = 0 dp2[n] dp2 n 0 d[n] = a d[n] d n a for i in range(N+1):
  for a, n in candidates:
    if i >= n and dp1[i-n]:
      if dp1[i] < dp1[i-n] + 1:
        dp1[i] = dp1[i-n] + 1
        dp2[i] = i-n i range(N+1) range N+1 N 1 for a, n in candidates:
    if i >= n and dp1[i-n]:
      if dp1[i] < dp1[i-n] + 1:
        dp1[i] = dp1[i-n] + 1
        dp2[i] = i-n a n candidates if i >= n and dp1[i-n]:
      if dp1[i] < dp1[i-n] + 1:
        dp1[i] = dp1[i-n] + 1
        dp2[i] = i-n i >= n and dp1[i-n] i >= n i n dp1[i-n] dp1 i-n i n if dp1[i] < dp1[i-n] + 1:
        dp1[i] = dp1[i-n] + 1
        dp2[i] = i-n dp1[i] < dp1[i-n] + 1 dp1[i] dp1 i dp1[i-n] + 1 dp1[i-n] dp1 i-n i n 1 dp1[i] = dp1[i-n] + 1 dp1[i] dp1 i dp1[i-n] + 1 dp1[i-n] dp1 i-n i n 1 dp2[i] = i-n dp2[i] dp2 i i-n i n ans = [] ans [] idx = N idx N while idx:
  next_idx = dp2[idx]
  ans.append(d[idx - next_idx])
  idx = next_idx idx next_idx = dp2[idx] next_idx dp2[idx] dp2 idx ans.append(d[idx - next_idx]) ans.append ans append d[idx - next_idx] d idx - next_idx idx next_idx idx = next_idx idx next_idx ans.sort(reverse=True) ans.sort ans sort reverse=True reverse True print(''.join(list(map(str, ans)))) print ''.join(list(map(str, ans))) ''.join '' join list(map(str, ans)) list map(str, ans) map str ans dp2 = [-1] * (N+1) [-1] * (N+1) dp2 dp1 = [0] * (N+1) [0] * (N+1) dp1 idx = next_idx next_idx idx nums = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] nums ans = [] [] ans N, M = map(int, input().split()) map(int, input().split()) N next_idx = dp2[idx] dp2[idx] next_idx candidates = [] [] candidates d = {} {} d M = map(int, input().split()) map(int, input().split()) M A = list(map(int, input().split())) list(map(int, input().split())) A s = set() set() s idx = N N idx
nums = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
N, M = map(int, input().split())
A = list(map(int, input().split()))

# 使うマッチ棒の本数が等しい場合は大きい数だけ考えれば良い
A.sort(reverse=True)
s = set()
candidates = [] # [a, nums[a]]
for a in A:
  if nums[a] in s:
    continue
  s.add(nums[a])
  candidates.append([a, nums[a]])


dp1 = [0] * (N+1)
dp2 = [-1] * (N+1)
d = {}
for a, n in candidates:
  if n <= N:
    dp1[n] = 1
    dp2[n] = 0
    d[n] = a

for i in range(N+1):
  for a, n in candidates:
    if i >= n and dp1[i-n]:
      if dp1[i] < dp1[i-n] + 1:
        dp1[i] = dp1[i-n] + 1
        dp2[i] = i-n

ans = []
idx = N
while idx:
  next_idx = dp2[idx]
  ans.append(d[idx - next_idx])
  idx = next_idx

ans.sort(reverse=True)
print(''.join(list(map(str, ans))))