n,m = map(int,input().split())
dp = [-10**5]*(n+1)
dp[0] = 0
t = [0,2,5,5,4,5,6,3,7,6]
a = set(map(int,input().split()))
for i in range(2,n+1):
  for x in a:
    if i-t[x] >= 0 and dp[i] < dp[i-t[x]] + 1:
      dp[i] = dp[i-t[x]] + 1
a = list(a)
a.sort(reverse=True)
cur = ""
idx = n
while idx:
  for x in a:
    if idx - t[x] >= 0 and dp[idx] == dp[idx-t[x]] + 1:
      cur += str(x)
      idx -= t[x]
      break
print(cur) n,m = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m dp = [-10**5]*(n+1) dp [-10**5]*(n+1) [-10**5] -10**5 -10 5 n+1 n 1 dp[0] = 0 dp[0] dp 0 0 t = [0,2,5,5,4,5,6,3,7,6] t [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 a = set(map(int,input().split())) a set(map(int,input().split())) set map(int,input().split()) map int input().split() ().split () input split for i in range(2,n+1):
  for x in a:
    if i-t[x] >= 0 and dp[i] < dp[i-t[x]] + 1:
      dp[i] = dp[i-t[x]] + 1 i range(2,n+1) range 2 n+1 n 1 for x in a:
    if i-t[x] >= 0 and dp[i] < dp[i-t[x]] + 1:
      dp[i] = dp[i-t[x]] + 1 x a if i-t[x] >= 0 and dp[i] < dp[i-t[x]] + 1:
      dp[i] = dp[i-t[x]] + 1 i-t[x] >= 0 and dp[i] < dp[i-t[x]] + 1 i-t[x] >= 0 i-t[x] i t[x] t x 0 dp[i] < dp[i-t[x]] + 1 dp[i] dp i dp[i-t[x]] + 1 dp[i-t[x]] dp i-t[x] i t[x] t x 1 dp[i] = dp[i-t[x]] + 1 dp[i] dp i dp[i-t[x]] + 1 dp[i-t[x]] dp i-t[x] i t[x] t x 1 a = list(a) a list(a) list a a.sort(reverse=True) a.sort a sort reverse=True reverse True cur = "" cur "" idx = n idx n while idx:
  for x in a:
    if idx - t[x] >= 0 and dp[idx] == dp[idx-t[x]] + 1:
      cur += str(x)
      idx -= t[x]
      break idx for x in a:
    if idx - t[x] >= 0 and dp[idx] == dp[idx-t[x]] + 1:
      cur += str(x)
      idx -= t[x]
      break x a if idx - t[x] >= 0 and dp[idx] == dp[idx-t[x]] + 1:
      cur += str(x)
      idx -= t[x]
      break idx - t[x] >= 0 and dp[idx] == dp[idx-t[x]] + 1 idx - t[x] >= 0 idx - t[x] idx t[x] t x 0 dp[idx] == dp[idx-t[x]] + 1 dp[idx] dp idx dp[idx-t[x]] + 1 dp[idx-t[x]] dp idx-t[x] idx t[x] t x 1 cur += str(x) cur str(x) str x idx -= t[x] idx t[x] t x break print(cur) print cur a = list(a) list(a) a m = map(int,input().split()) map(int,input().split()) m n,m = map(int,input().split()) map(int,input().split()) n idx -= t[x] t[x] idx t = [0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] t a = set(map(int,input().split())) set(map(int,input().split())) a cur += str(x) str(x) cur dp = [-10**5]*(n+1) [-10**5]*(n+1) dp idx = n n idx cur = "" "" cur
n,m = map(int,input().split())
dp = [-10**5]*(n+1)
dp[0] = 0
t = [0,2,5,5,4,5,6,3,7,6]
a = set(map(int,input().split()))
for i in range(2,n+1):
  for x in a:
    if i-t[x] >= 0 and dp[i] < dp[i-t[x]] + 1:
      dp[i] = dp[i-t[x]] + 1
a = list(a)
a.sort(reverse=True)
cur = ""
idx = n
while idx:
  for x in a:
    if idx - t[x] >= 0 and dp[idx] == dp[idx-t[x]] + 1:
      cur += str(x)
      idx -= t[x]
      break
print(cur)