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

C = [0,2,5,5,4,5,6,3,7,6]
dp = [-1]*(n+1)
dp[0] = 0

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

C = [0,2,5,5,4,5,6,3,7,6]
dp = [-1]*(n+1)
dp[0] = 0

for n_i in range(n):
  for a_i in A:
    if n_i+C[a_i]<=n:
      dp[n_i+C[a_i]] = max(dp[n_i+C[a_i]], dp[n_i]*10+a_i)
      
print(dp.pop())