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

a = [0,2,5,5,4,5,6,3,7,6]

kazu = [a[List[i]] for i in range(M)]

def dddd(kazu,X):
  dp = [ [ -float('inf') for j in range(X+1)]  for i in range(M)]
  for i in range(M):
    dp[i][0] = 0

  for i in range(M):
    for j in range(X+1):
      if kazu[i] <= j:
        dp[i][j] = max(dp[i][j-kazu[i]] + 1,dp[i-1][j])
      else:
        dp[i][j] = dp[i-1][j]
  return dp[-1]
   
keta_arr = dddd(kazu,N)
keta = keta_arr[-1]
List.sort(reverse=True)
ans = []

while keta>0:
  for aa in List:
    k = a[aa]
    if N-k < 0:
      continue
    if N-k >= 0:
      if keta_arr[N-k] == keta-1:       
        ans.append(aa)
        N = N-k
        keta -= 1
        break
ans.sort(reverse=True)
print(int(''.join(map(str,ans)))) N,M = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M List = list(map(int,input().split())) List list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split a = [0,2,5,5,4,5,6,3,7,6] a [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 a[List[i]] for i in range(M) for i in range(M) i range(M) range M for i in range(M) a[List[i]] a List[i] List i kazu = [a[List[i]] for i in range(M)] kazu [a[List[i]] for i in range(M)] def dddd(kazu,X):
  dp = [ [ -float('inf') for j in range(X+1)]  for i in range(M)]
  for i in range(M):
    dp[i][0] = 0

  for i in range(M):
    for j in range(X+1):
      if kazu[i] <= j:
        dp[i][j] = max(dp[i][j-kazu[i]] + 1,dp[i-1][j])
      else:
        dp[i][j] = dp[i-1][j]
  return dp[-1]
    dddd [ -float('inf') for j in range(X+1)]  for i in range(M) for i in range(M) i range(M) range M for i in range(M) [ -float('inf') for j in range(X+1)] dp = [ [ -float('inf') for j in range(X+1)]  for i in range(M)] dp [ [ -float('inf') for j in range(X+1)]  for i in range(M)] for i in range(M):
    dp[i][0] = 0

   i range(M) range M dp[i][0] = 0 dp[i][0] [i] dp i 0 0 for i in range(M):
    for j in range(X+1):
      if kazu[i] <= j:
        dp[i][j] = max(dp[i][j-kazu[i]] + 1,dp[i-1][j])
      else:
        dp[i][j] = dp[i-1][j]
   i range(M) range M for j in range(X+1):
      if kazu[i] <= j:
        dp[i][j] = max(dp[i][j-kazu[i]] + 1,dp[i-1][j])
      else:
        dp[i][j] = dp[i-1][j]
   j range(X+1) range X+1 X 1 if kazu[i] <= j:
        dp[i][j] = max(dp[i][j-kazu[i]] + 1,dp[i-1][j])
      else:
        dp[i][j] = dp[i-1][j]
   kazu[i] <= j kazu[i] kazu i j dp[i][j] = max(dp[i][j-kazu[i]] + 1,dp[i-1][j]) dp[i][j] [i] dp i j max(dp[i][j-kazu[i]] + 1,dp[i-1][j]) max dp[i][j-kazu[i]] + 1 dp[i][j-kazu[i]] [i] dp i j-kazu[i] j kazu[i] kazu i 1 dp[i-1][j] [i-1] dp i-1 i 1 j dp[i][j] = dp[i-1][j] dp[i][j] [i] dp i j dp[i-1][j] [i-1] dp i-1 i 1 j return dp[-1] dp[-1] dp -1 kazu kazu X X keta_arr = dddd(kazu,N) keta_arr dddd(kazu,N) dddd kazu N keta = keta_arr[-1] keta keta_arr[-1] keta_arr -1 List.sort(reverse=True) List.sort List sort reverse=True reverse True ans = [] ans [] while keta>0:
  for aa in List:
    k = a[aa]
    if N-k < 0:
      continue
    if N-k >= 0:
      if keta_arr[N-k] == keta-1:       
        ans.append(aa)
        N = N-k
        keta -= 1
        break keta>0 keta 0 for aa in List:
    k = a[aa]
    if N-k < 0:
      continue
    if N-k >= 0:
      if keta_arr[N-k] == keta-1:       
        ans.append(aa)
        N = N-k
        keta -= 1
        break aa List k = a[aa] k a[aa] a aa if N-k < 0:
      continue
     N-k < 0 N-k N k 0 continue if N-k >= 0:
      if keta_arr[N-k] == keta-1:       
        ans.append(aa)
        N = N-k
        keta -= 1
        break N-k >= 0 N-k N k 0 if keta_arr[N-k] == keta-1:       
        ans.append(aa)
        N = N-k
        keta -= 1
        break keta_arr[N-k] == keta-1 keta_arr[N-k] keta_arr N-k N k keta-1 keta 1 ans.append(aa) ans.append ans append aa N = N-k N N-k N k keta -= 1 keta 1 break ans.sort(reverse=True) ans.sort ans sort reverse=True reverse True print(int(''.join(map(str,ans)))) print int(''.join(map(str,ans))) int ''.join(map(str,ans)) ''.join '' join map(str,ans) map str ans keta_arr = dddd(kazu,N) dddd(kazu,N) keta_arr N = N-k N-k N keta -= 1 1 keta a = [0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] a kazu = [a[List[i]] for i in range(M)] [a[List[i]] for i in range(M)] kazu def dddd(kazu,X):
  dp = [ [ -float('inf') for j in range(X+1)]  for i in range(M)]
  for i in range(M):
    dp[i][0] = 0

  for i in range(M):
    for j in range(X+1):
      if kazu[i] <= j:
        dp[i][j] = max(dp[i][j-kazu[i]] + 1,dp[i-1][j])
      else:
        dp[i][j] = dp[i-1][j]
  return dp[-1]
    def dddd(kazu,X):
  dp = [ [ -float('inf') for j in range(X+1)]  for i in range(M)]
  for i in range(M):
    dp[i][0] = 0

  for i in range(M):
    for j in range(X+1):
      if kazu[i] <= j:
        dp[i][j] = max(dp[i][j-kazu[i]] + 1,dp[i-1][j])
      else:
        dp[i][j] = dp[i-1][j]
  return dp[-1]
    dddd k = a[aa] a[aa] k keta = keta_arr[-1] keta_arr[-1] keta N,M = map(int,input().split()) map(int,input().split()) N M = map(int,input().split()) map(int,input().split()) M List = list(map(int,input().split())) list(map(int,input().split())) List ans = [] [] ans
N,M = map(int,input().split())
List = list(map(int,input().split()))

a = [0,2,5,5,4,5,6,3,7,6]

kazu = [a[List[i]] for i in range(M)]

def dddd(kazu,X):
  dp = [ [ -float('inf') for j in range(X+1)]  for i in range(M)]
  for i in range(M):
    dp[i][0] = 0

  for i in range(M):
    for j in range(X+1):
      if kazu[i] <= j:
        dp[i][j] = max(dp[i][j-kazu[i]] + 1,dp[i-1][j])
      else:
        dp[i][j] = dp[i-1][j]
  return dp[-1]
   
keta_arr = dddd(kazu,N)
keta = keta_arr[-1]
List.sort(reverse=True)
ans = []

while keta>0:
  for aa in List:
    k = a[aa]
    if N-k < 0:
      continue
    if N-k >= 0:
      if keta_arr[N-k] == keta-1:       
        ans.append(aa)
        N = N-k
        keta -= 1
        break
ans.sort(reverse=True)
print(int(''.join(map(str,ans))))