N, M = map(int, input().split())
a = [int(i) for i in input().split()]

dic = {}
dic[1] = 2
dic[2] = 5
dic[3] = 5
dic[4] = 4
dic[5] = 5
dic[6] = 6
dic[7] = 3
dic[8] = 7
dic[9] = 6

ls = [-1]*8
dp = [-1]*(N+1)
dp[0] = 0
for i in a:
  j = dic[i]
  if ls[j]<i:
    ls[j] = i

tag = []
for i in range(len(ls)):
  if ls[i]!=-1:
    tag += [i]
for i in range(N+1):
  for j in tag:
    if i+j<=N:
      dp[i+j] = max(dp[i]*10+ls[j], dp[i+j])

print(dp[N]) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i a = [int(i) for i in input().split()] a [int(i) for i in input().split()] dic = {} dic {} dic[1] = 2 dic[1] dic 1 2 dic[2] = 5 dic[2] dic 2 5 dic[3] = 5 dic[3] dic 3 5 dic[4] = 4 dic[4] dic 4 4 dic[5] = 5 dic[5] dic 5 5 dic[6] = 6 dic[6] dic 6 6 dic[7] = 3 dic[7] dic 7 3 dic[8] = 7 dic[8] dic 8 7 dic[9] = 6 dic[9] dic 9 6 ls = [-1]*8 ls [-1]*8 [-1] -1 8 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 a:
  j = dic[i]
  if ls[j]<i:
    ls[j] = i i a j = dic[i] j dic[i] dic i if ls[j]<i:
    ls[j] = i ls[j]<i ls[j] ls j i ls[j] = i ls[j] ls j i tag = [] tag [] for i in range(len(ls)):
  if ls[i]!=-1:
    tag += [i] i range(len(ls)) range len(ls) len ls if ls[i]!=-1:
    tag += [i] ls[i]!=-1 ls[i] ls i -1 tag += [i] tag [i] i for i in range(N+1):
  for j in tag:
    if i+j<=N:
      dp[i+j] = max(dp[i]*10+ls[j], dp[i+j]) i range(N+1) range N+1 N 1 for j in tag:
    if i+j<=N:
      dp[i+j] = max(dp[i]*10+ls[j], dp[i+j]) j tag if i+j<=N:
      dp[i+j] = max(dp[i]*10+ls[j], dp[i+j]) i+j<=N i+j i j N dp[i+j] = max(dp[i]*10+ls[j], dp[i+j]) dp[i+j] dp i+j i j max(dp[i]*10+ls[j], dp[i+j]) max dp[i]*10+ls[j] dp[i]*10 dp[i] dp i 10 ls[j] ls j dp[i+j] dp i+j i j print(dp[N]) print dp[N] dp N M = map(int, input().split()) map(int, input().split()) M j = dic[i] dic[i] j dic = {} {} dic a = [int(i) for i in input().split()] [int(i) for i in input().split()] a ls = [-1]*8 [-1]*8 ls dp = [-1]*(N+1) [-1]*(N+1) dp tag += [i] [i] tag N, M = map(int, input().split()) map(int, input().split()) N tag = [] [] tag
N, M = map(int, input().split())
a = [int(i) for i in input().split()]

dic = {}
dic[1] = 2
dic[2] = 5
dic[3] = 5
dic[4] = 4
dic[5] = 5
dic[6] = 6
dic[7] = 3
dic[8] = 7
dic[9] = 6

ls = [-1]*8
dp = [-1]*(N+1)
dp[0] = 0
for i in a:
  j = dic[i]
  if ls[j]<i:
    ls[j] = i

tag = []
for i in range(len(ls)):
  if ls[i]!=-1:
    tag += [i]
for i in range(N+1):
  for j in tag:
    if i+j<=N:
      dp[i+j] = max(dp[i]*10+ls[j], dp[i+j])

print(dp[N])
