n, m = map(int, input().split())
D = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
A = list(map(int, input().split()))
C = [(a, D[a]) for a in A]
C.sort(reverse=True)
dp = [-1]*(n+1)
dp[0] = 0
for i in range(1, n+1):
  for a, c in C:
    if i >= c and dp[i-c] >= 0:
      dp[i] = max(dp[i-c]+1, dp[i])
now = n
ans = ""
while now:
  for a, c in C:
    if now-c >= 0 and dp[now] == dp[now-c]+1:
      ans += str(a)
      now -= c
      break
print(ans) n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m D = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] D [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] 0 2 5 5 4 5 6 3 7 6 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, D[a]) for a in A for a in A a A for a in A (a, D[a]) a D[a] D a C = [(a, D[a]) for a in A] C [(a, D[a]) for a in A] C.sort(reverse=True) C.sort C sort reverse=True reverse True 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(1, n+1):
  for a, c in C:
    if i >= c and dp[i-c] >= 0:
      dp[i] = max(dp[i-c]+1, dp[i]) i range(1, n+1) range 1 n+1 n 1 for a, c in C:
    if i >= c and dp[i-c] >= 0:
      dp[i] = max(dp[i-c]+1, dp[i]) a c C if i >= c and dp[i-c] >= 0:
      dp[i] = max(dp[i-c]+1, dp[i]) i >= c and dp[i-c] >= 0 i >= c i c dp[i-c] >= 0 dp[i-c] dp i-c i c 0 dp[i] = max(dp[i-c]+1, dp[i]) dp[i] dp i max(dp[i-c]+1, dp[i]) max dp[i-c]+1 dp[i-c] dp i-c i c 1 dp[i] dp i now = n now n ans = "" ans "" while now:
  for a, c in C:
    if now-c >= 0 and dp[now] == dp[now-c]+1:
      ans += str(a)
      now -= c
      break now for a, c in C:
    if now-c >= 0 and dp[now] == dp[now-c]+1:
      ans += str(a)
      now -= c
      break a c C if now-c >= 0 and dp[now] == dp[now-c]+1:
      ans += str(a)
      now -= c
      break now-c >= 0 and dp[now] == dp[now-c]+1 now-c >= 0 now-c now c 0 dp[now] == dp[now-c]+1 dp[now] dp now dp[now-c]+1 dp[now-c] dp now-c now c 1 ans += str(a) ans str(a) str a now -= c now c break print(ans) print ans m = map(int, input().split()) map(int, input().split()) m n, m = map(int, input().split()) map(int, input().split()) n D = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] D ans += str(a) str(a) ans C = [(a, D[a]) for a in A] [(a, D[a]) for a in A] C now -= c c now now = n n now A = list(map(int, input().split())) list(map(int, input().split())) A dp = [-1]*(n+1) [-1]*(n+1) dp ans = "" "" ans
n, m = map(int, input().split())
D = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
A = list(map(int, input().split()))
C = [(a, D[a]) for a in A]
C.sort(reverse=True)
dp = [-1]*(n+1)
dp[0] = 0
for i in range(1, n+1):
  for a, c in C:
    if i >= c and dp[i-c] >= 0:
      dp[i] = max(dp[i-c]+1, dp[i])
now = n
ans = ""
while now:
  for a, c in C:
    if now-c >= 0 and dp[now] == dp[now-c]+1:
      ans += str(a)
      now -= c
      break
print(ans)