N,M=map(int,input().split())
A=list(map(int,input().split()))

if N % 2 == 0:
  if 1 in A:
    print(int('1'*(N//2)))
    exit()

need =(2,5,5,4,5,6,3,7,6)

if 2 in A and 3 in A:
  del A[A.index(2)]
if 3 in A and 5 in A:
  del A[A.index(3)]
if 6 in A and 9 in A:
  del A[A.index(6)]
if 1 in A and 4 in A:
  del A[A.index(4)]
if 6 in A and 7 in A:
  del A[A.index(6)] 
if 7 in A and 9 in A:
  del A[A.index(9)] 
if 1 in A and 6 in A:
  del A[A.index(6)] 
if 1 in A and 9 in A:
  del A[A.index(9)] 
  
A = tuple(A)
M = len(A)

dp = [[0]*(N+1) for _ in range(M)]
dpmax = [0]*(N+1)

def take_max():
  return max(A[i]*(10**len(str(tmp2)) + tmp2,tmp2*10+A[i]))

for j in range(2,N+1):
  tmpmax = 0
  for i in range(M):
    tmp = need[A[i]-1]
    if j == tmp:
      dp[i][j] = A[i]
    elif j > tmp:
      if dpmax[j-tmp] != 0:
        tmp2 = dpmax[j-tmp]
        dp[i][j] = take_max()
    if tmpmax < dp[i][j]:
      tmpmax = dp[i][j]
  dpmax[j] = tmpmax
  
print(dpmax[-1]) 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 if N % 2 == 0:
  if 1 in A:
    print(int('1'*(N//2)))
    exit() N % 2 == 0 N % 2 N 2 0 if 1 in A:
    print(int('1'*(N//2)))
    exit() 1 in A 1 A print(int('1'*(N//2))) print int('1'*(N//2)) int '1'*(N//2) '1' N//2 N 2 exit() exit need =(2,5,5,4,5,6,3,7,6) need (2,5,5,4,5,6,3,7,6) 2 5 5 4 5 6 3 7 6 if 2 in A and 3 in A:
  del A[A.index(2)] 2 in A and 3 in A 2 in A 2 A 3 in A 3 A del A[A.index(2)] A[A.index(2)] A A.index(2) A.index A index 2 if 3 in A and 5 in A:
  del A[A.index(3)] 3 in A and 5 in A 3 in A 3 A 5 in A 5 A del A[A.index(3)] A[A.index(3)] A A.index(3) A.index A index 3 if 6 in A and 9 in A:
  del A[A.index(6)] 6 in A and 9 in A 6 in A 6 A 9 in A 9 A del A[A.index(6)] A[A.index(6)] A A.index(6) A.index A index 6 if 1 in A and 4 in A:
  del A[A.index(4)] 1 in A and 4 in A 1 in A 1 A 4 in A 4 A del A[A.index(4)] A[A.index(4)] A A.index(4) A.index A index 4 if 6 in A and 7 in A:
  del A[A.index(6)]  6 in A and 7 in A 6 in A 6 A 7 in A 7 A del A[A.index(6)] A[A.index(6)] A A.index(6) A.index A index 6 if 7 in A and 9 in A:
  del A[A.index(9)]  7 in A and 9 in A 7 in A 7 A 9 in A 9 A del A[A.index(9)] A[A.index(9)] A A.index(9) A.index A index 9 if 1 in A and 6 in A:
  del A[A.index(6)]  1 in A and 6 in A 1 in A 1 A 6 in A 6 A del A[A.index(6)] A[A.index(6)] A A.index(6) A.index A index 6 if 1 in A and 9 in A:
  del A[A.index(9)] 
   1 in A and 9 in A 1 in A 1 A 9 in A 9 A del A[A.index(9)] A[A.index(9)] A A.index(9) A.index A index 9 A = tuple(A) A tuple(A) tuple A M = len(A) M len(A) len A [0]*(N+1) for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) [0]*(N+1) [0] 0 N+1 N 1 dp = [[0]*(N+1) for _ in range(M)] dp [[0]*(N+1) for _ in range(M)] dpmax = [0]*(N+1) dpmax [0]*(N+1) [0] 0 N+1 N 1 def take_max():
  return max(A[i]*(10**len(str(tmp2)) + tmp2,tmp2*10+A[i])) take_max return max(A[i]*(10**len(str(tmp2)) + tmp2,tmp2*10+A[i])) max(A[i]*(10**len(str(tmp2)) + tmp2,tmp2*10+A[i])) max A[i]*(10**len(str(tmp2)) + tmp2,tmp2*10+A[i]) A[i] A i (10**len(str(tmp2)) + tmp2,tmp2*10+A[i]) 10**len(str(tmp2)) + tmp2 10**len(str(tmp2)) 10 len(str(tmp2)) len str(tmp2) str tmp2 tmp2 tmp2*10+A[i] tmp2*10 tmp2 10 A[i] A i for j in range(2,N+1):
  tmpmax = 0
  for i in range(M):
    tmp = need[A[i]-1]
    if j == tmp:
      dp[i][j] = A[i]
    elif j > tmp:
      if dpmax[j-tmp] != 0:
        tmp2 = dpmax[j-tmp]
        dp[i][j] = take_max()
    if tmpmax < dp[i][j]:
      tmpmax = dp[i][j]
  dpmax[j] = tmpmax
   j range(2,N+1) range 2 N+1 N 1 tmpmax = 0 tmpmax 0 for i in range(M):
    tmp = need[A[i]-1]
    if j == tmp:
      dp[i][j] = A[i]
    elif j > tmp:
      if dpmax[j-tmp] != 0:
        tmp2 = dpmax[j-tmp]
        dp[i][j] = take_max()
    if tmpmax < dp[i][j]:
      tmpmax = dp[i][j]
   i range(M) range M tmp = need[A[i]-1] tmp need[A[i]-1] need A[i]-1 A[i] A i 1 if j == tmp:
      dp[i][j] = A[i]
    elif j > tmp:
      if dpmax[j-tmp] != 0:
        tmp2 = dpmax[j-tmp]
        dp[i][j] = take_max()
     j == tmp j tmp dp[i][j] = A[i] dp[i][j] [i] dp i j A[i] A i elif j > tmp:
      if dpmax[j-tmp] != 0:
        tmp2 = dpmax[j-tmp]
        dp[i][j] = take_max()
     j > tmp j tmp if dpmax[j-tmp] != 0:
        tmp2 = dpmax[j-tmp]
        dp[i][j] = take_max()
     dpmax[j-tmp] != 0 dpmax[j-tmp] dpmax j-tmp j tmp 0 tmp2 = dpmax[j-tmp] tmp2 dpmax[j-tmp] dpmax j-tmp j tmp dp[i][j] = take_max() dp[i][j] [i] dp i j take_max() take_max if tmpmax < dp[i][j]:
      tmpmax = dp[i][j]
   tmpmax < dp[i][j] tmpmax dp[i][j] [i] dp i j tmpmax = dp[i][j] tmpmax dp[i][j] [i] dp i j dpmax[j] = tmpmax dpmax[j] dpmax j tmpmax print(dpmax[-1]) print dpmax[-1] dpmax -1 M=map(int,input().split()) map(int,input().split()) M tmp = need[A[i]-1] need[A[i]-1] tmp dp = [[0]*(N+1) for _ in range(M)] [[0]*(N+1) for _ in range(M)] dp M = len(A) len(A) M dpmax = [0]*(N+1) [0]*(N+1) dpmax need =(2,5,5,4,5,6,3,7,6) (2,5,5,4,5,6,3,7,6) need tmp2 = dpmax[j-tmp] dpmax[j-tmp] tmp2 A=list(map(int,input().split())) list(map(int,input().split())) A N,M=map(int,input().split()) map(int,input().split()) N tmpmax = 0 0 tmpmax def take_max():
  return max(A[i]*(10**len(str(tmp2)) + tmp2,tmp2*10+A[i])) def take_max():
  return max(A[i]*(10**len(str(tmp2)) + tmp2,tmp2*10+A[i])) take_max tmpmax = dp[i][j] dp[i][j] tmpmax A = tuple(A) tuple(A) A
N,M=map(int,input().split())
A=list(map(int,input().split()))

if N % 2 == 0:
  if 1 in A:
    print(int('1'*(N//2)))
    exit()

need =(2,5,5,4,5,6,3,7,6)

if 2 in A and 3 in A:
  del A[A.index(2)]
if 3 in A and 5 in A:
  del A[A.index(3)]
if 6 in A and 9 in A:
  del A[A.index(6)]
if 1 in A and 4 in A:
  del A[A.index(4)]
if 6 in A and 7 in A:
  del A[A.index(6)] 
if 7 in A and 9 in A:
  del A[A.index(9)] 
if 1 in A and 6 in A:
  del A[A.index(6)] 
if 1 in A and 9 in A:
  del A[A.index(9)] 
  
A = tuple(A)
M = len(A)

dp = [[0]*(N+1) for _ in range(M)]
dpmax = [0]*(N+1)

def take_max():
  return max(A[i]*(10**len(str(tmp2)) + tmp2,tmp2*10+A[i]))

for j in range(2,N+1):
  tmpmax = 0
  for i in range(M):
    tmp = need[A[i]-1]
    if j == tmp:
      dp[i][j] = A[i]
    elif j > tmp:
      if dpmax[j-tmp] != 0:
        tmp2 = dpmax[j-tmp]
        dp[i][j] = take_max()
    if tmpmax < dp[i][j]:
      tmpmax = dp[i][j]
  dpmax[j] = tmpmax
  
print(dpmax[-1])