from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)


n,m = inm()
a = inl()
a.sort()
cs = [0,2,5,5,4,5,6,3,7,6]
dp = [-1]*(n+9)
dp[0] = 0
for i in range(n):
    if dp[i]>=0:
        for x in a:
            c = cs[x]
            dp[i+c] = max(dp[i+c], dp[i]+1)
ans = []
t = n
k = dp[n]
for j in range(k,0,-1):
    for i in range(m-1,-1,-1):
        x = a[i]
        c = cs[x]
        if t>=c and dp[t-c]==j-1:
            ans.append(str(x))
            t -= c
            break
print(''.join(ans)) from sys import stdout printn = lambda x: stdout.write(str(x)) printn lambda x: stdout.write(str(x)) stdout.write(str(x)) stdout.write stdout write str(x) str x x inn = lambda : int(input()) inn lambda : int(input()) int(input()) int input() input inl   = lambda: list(map(int, input().split())) inl lambda: list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split inm   = lambda:      map(int, input().split()) inm lambda:      map(int, input().split()) map(int, input().split()) map int input().split() ().split () input split ins = lambda : input().strip() ins lambda : input().strip() input().strip() ().strip () input strip DBG = True DBG True BIG = 999999999 BIG 999999999 R = 10**9 + 7 R 10**9 + 7 10**9 10 9 7 def ddprint(x):
  if DBG:
    print(x) ddprint if DBG:
    print(x) DBG print(x) print x x x n,m = inm() n inm() inm m a = inl() a inl() inl a.sort() a.sort a sort cs = [0,2,5,5,4,5,6,3,7,6] cs [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 dp = [-1]*(n+9) dp [-1]*(n+9) [-1] -1 n+9 n 9 dp[0] = 0 dp[0] dp 0 0 for i in range(n):
    if dp[i]>=0:
        for x in a:
            c = cs[x]
            dp[i+c] = max(dp[i+c], dp[i]+1) i range(n) range n if dp[i]>=0:
        for x in a:
            c = cs[x]
            dp[i+c] = max(dp[i+c], dp[i]+1) dp[i]>=0 dp[i] dp i 0 for x in a:
            c = cs[x]
            dp[i+c] = max(dp[i+c], dp[i]+1) x a c = cs[x] c cs[x] cs x dp[i+c] = max(dp[i+c], dp[i]+1) dp[i+c] dp i+c i c max(dp[i+c], dp[i]+1) max dp[i+c] dp i+c i c dp[i]+1 dp[i] dp i 1 ans = [] ans [] t = n t n k = dp[n] k dp[n] dp n for j in range(k,0,-1):
    for i in range(m-1,-1,-1):
        x = a[i]
        c = cs[x]
        if t>=c and dp[t-c]==j-1:
            ans.append(str(x))
            t -= c
            break j range(k,0,-1) range k 0 -1 for i in range(m-1,-1,-1):
        x = a[i]
        c = cs[x]
        if t>=c and dp[t-c]==j-1:
            ans.append(str(x))
            t -= c
            break i range(m-1,-1,-1) range m-1 m 1 -1 -1 x = a[i] x a[i] a i c = cs[x] c cs[x] cs x if t>=c and dp[t-c]==j-1:
            ans.append(str(x))
            t -= c
            break t>=c and dp[t-c]==j-1 t>=c t c dp[t-c]==j-1 dp[t-c] dp t-c t c j-1 j 1 ans.append(str(x)) ans.append ans append str(x) str x t -= c t c break print(''.join(ans)) print ''.join(ans) ''.join '' join ans inl   = lambda: list(map(int, input().split())) lambda: list(map(int, input().split())) inl BIG = 999999999 999999999 BIG m = inm() inm() m n,m = inm() inm() n cs = [0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] cs ins = lambda : input().strip() lambda : input().strip() ins k = dp[n] dp[n] k x = a[i] a[i] x DBG = True True DBG inn = lambda : int(input()) lambda : int(input()) inn R = 10**9 + 7 10**9 + 7 R a = inl() inl() a ans = [] [] ans def ddprint(x):
  if DBG:
    print(x) def ddprint(x):
  if DBG:
    print(x) ddprint c = cs[x] cs[x] c inm   = lambda:      map(int, input().split()) lambda:      map(int, input().split()) inm dp = [-1]*(n+9) [-1]*(n+9) dp c = cs[x] cs[x] c t = n n t t -= c c t printn = lambda x: stdout.write(str(x)) lambda x: stdout.write(str(x)) printn
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)


n,m = inm()
a = inl()
a.sort()
cs = [0,2,5,5,4,5,6,3,7,6]
dp = [-1]*(n+9)
dp[0] = 0
for i in range(n):
    if dp[i]>=0:
        for x in a:
            c = cs[x]
            dp[i+c] = max(dp[i+c], dp[i]+1)
ans = []
t = n
k = dp[n]
for j in range(k,0,-1):
    for i in range(m-1,-1,-1):
        x = a[i]
        c = cs[x]
        if t>=c and dp[t-c]==j-1:
            ans.append(str(x))
            t -= c
            break
print(''.join(ans))
