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]])


dp = [-1] * (N+1)
dp[0] = 0
for i in range(N+1):
  for a, n in candidates:
    if i >= n and dp[i-n]>=0:
      dp[i] = max(dp[i], dp[i-n]+1)

ans = ''
idx = N
digit = dp[N]
while digit:
  for a, n in candidates:
    if idx - n >= 0 and dp[idx-n] == dp[idx]-1:
      ans += str(a)
      digit -= 1
      idx -= n
      break

print(int(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 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+1):
  for a, n in candidates:
    if i >= n and dp[i-n]>=0:
      dp[i] = max(dp[i], dp[i-n]+1) i range(N+1) range N+1 N 1 for a, n in candidates:
    if i >= n and dp[i-n]>=0:
      dp[i] = max(dp[i], dp[i-n]+1) a n candidates if i >= n and dp[i-n]>=0:
      dp[i] = max(dp[i], dp[i-n]+1) i >= n and dp[i-n]>=0 i >= n i n dp[i-n]>=0 dp[i-n] dp i-n i n 0 dp[i] = max(dp[i], dp[i-n]+1) dp[i] dp i max(dp[i], dp[i-n]+1) max dp[i] dp i dp[i-n]+1 dp[i-n] dp i-n i n 1 ans = '' ans '' idx = N idx N digit = dp[N] digit dp[N] dp N while digit:
  for a, n in candidates:
    if idx - n >= 0 and dp[idx-n] == dp[idx]-1:
      ans += str(a)
      digit -= 1
      idx -= n
      break digit for a, n in candidates:
    if idx - n >= 0 and dp[idx-n] == dp[idx]-1:
      ans += str(a)
      digit -= 1
      idx -= n
      break a n candidates if idx - n >= 0 and dp[idx-n] == dp[idx]-1:
      ans += str(a)
      digit -= 1
      idx -= n
      break idx - n >= 0 and dp[idx-n] == dp[idx]-1 idx - n >= 0 idx - n idx n 0 dp[idx-n] == dp[idx]-1 dp[idx-n] dp idx-n idx n dp[idx]-1 dp[idx] dp idx 1 ans += str(a) ans str(a) str a digit -= 1 digit 1 idx -= n idx n break print(int(ans)) print int(ans) int ans digit -= 1 1 digit A = list(map(int, input().split())) list(map(int, input().split())) A ans += str(a) str(a) ans idx = N N idx M = map(int, input().split()) map(int, input().split()) M idx -= n n idx N, M = map(int, input().split()) map(int, input().split()) N nums = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] nums dp = [-1] * (N+1) [-1] * (N+1) dp digit = dp[N] dp[N] digit ans = '' '' ans s = set() set() s candidates = [] [] candidates
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]])


dp = [-1] * (N+1)
dp[0] = 0
for i in range(N+1):
  for a, n in candidates:
    if i >= n and dp[i-n]>=0:
      dp[i] = max(dp[i], dp[i-n]+1)

ans = ''
idx = N
digit = dp[N]
while digit:
  for a, n in candidates:
    if idx - n >= 0 and dp[idx-n] == dp[idx]-1:
      ans += str(a)
      digit -= 1
      idx -= n
      break

print(int(ans))