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


dp = ["-" for i in range(11000)]
dp[0] = ""

def cal(x, y):
  lenx = len(x)
  leny = len(y)
  
  if lenx > leny:
    return x
  if leny > lenx:
    return y
  
  return max(x, y)

for i in range(N):
  if dp[i] == "-": 
    continue

  for j in range(M):
    num = numbers[A[j]]
    dp[i+num] = cal(dp[i] + str(A[j]), dp[i+num])

print(dp[N]) 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 numbers = [0,2,5,5,4,5,6,3,7,6] numbers [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 "-" for i in range(11000) for i in range(11000) i range(11000) range 11000 for i in range(11000) "-" dp = ["-" for i in range(11000)] dp ["-" for i in range(11000)] dp[0] = "" dp[0] dp 0 "" def cal(x, y):
  lenx = len(x)
  leny = len(y)
  
  if lenx > leny:
    return x
  if leny > lenx:
    return y
  
  return max(x, y) cal lenx = len(x) lenx len(x) len x leny = len(y) leny len(y) len y if lenx > leny:
    return x
   lenx > leny lenx leny return x x if leny > lenx:
    return y
  
   leny > lenx leny lenx return y y return max(x, y) max(x, y) max x y x x y y for i in range(N):
  if dp[i] == "-": 
    continue

  for j in range(M):
    num = numbers[A[j]]
    dp[i+num] = cal(dp[i] + str(A[j]), dp[i+num]) i range(N) range N if dp[i] == "-": 
    continue

   dp[i] == "-" dp[i] dp i "-" continue for j in range(M):
    num = numbers[A[j]]
    dp[i+num] = cal(dp[i] + str(A[j]), dp[i+num]) j range(M) range M num = numbers[A[j]] num numbers[A[j]] numbers A[j] A j dp[i+num] = cal(dp[i] + str(A[j]), dp[i+num]) dp[i+num] dp i+num i num cal(dp[i] + str(A[j]), dp[i+num]) cal dp[i] + str(A[j]) dp[i] dp i str(A[j]) str A[j] A j dp[i+num] dp i+num i num print(dp[N]) print dp[N] dp N num = numbers[A[j]] numbers[A[j]] num numbers = [0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] numbers def cal(x, y):
  lenx = len(x)
  leny = len(y)
  
  if lenx > leny:
    return x
  if leny > lenx:
    return y
  
  return max(x, y) def cal(x, y):
  lenx = len(x)
  leny = len(y)
  
  if lenx > leny:
    return x
  if leny > lenx:
    return y
  
  return max(x, y) cal N, M = map(int, input().split()) map(int, input().split()) N A = list(map(int, input().split())) list(map(int, input().split())) A M = map(int, input().split()) map(int, input().split()) M dp = ["-" for i in range(11000)] ["-" for i in range(11000)] dp

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


dp = ["-" for i in range(11000)]
dp[0] = ""

def cal(x, y):
  lenx = len(x)
  leny = len(y)
  
  if lenx > leny:
    return x
  if leny > lenx:
    return y
  
  return max(x, y)

for i in range(N):
  if dp[i] == "-": 
    continue

  for j in range(M):
    num = numbers[A[j]]
    dp[i+num] = cal(dp[i] + str(A[j]), dp[i+num])

print(dp[N])