n,m = map(int,input().split())
a = set(map(int,input().split()))
dp = [0]+[-float('inf')]*n
f = [0,2,5,5,4,5,6,3,7,6]
for i in range(n+1):
  for j in a:
    F = f[j]
    if F <= i:
      dp[i] = max(dp[i-F]*10+j,dp[i])
print(dp[n]) n,m = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m a = set(map(int,input().split())) a set(map(int,input().split())) set map(int,input().split()) map int input().split() ().split () input split dp = [0]+[-float('inf')]*n dp [0]+[-float('inf')]*n [0] 0 [-float('inf')]*n [-float('inf')] -float('inf') float('inf') float 'inf' n f = [0,2,5,5,4,5,6,3,7,6] f [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 for i in range(n+1):
  for j in a:
    F = f[j]
    if F <= i:
      dp[i] = max(dp[i-F]*10+j,dp[i]) i range(n+1) range n+1 n 1 for j in a:
    F = f[j]
    if F <= i:
      dp[i] = max(dp[i-F]*10+j,dp[i]) j a F = f[j] F f[j] f j if F <= i:
      dp[i] = max(dp[i-F]*10+j,dp[i]) F <= i F i dp[i] = max(dp[i-F]*10+j,dp[i]) dp[i] dp i max(dp[i-F]*10+j,dp[i]) max dp[i-F]*10+j dp[i-F]*10 dp[i-F] dp i-F i F 10 j dp[i] dp i print(dp[n]) print dp[n] dp n f = [0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] f a = set(map(int,input().split())) set(map(int,input().split())) a m = map(int,input().split()) map(int,input().split()) m n,m = map(int,input().split()) map(int,input().split()) n F = f[j] f[j] F dp = [0]+[-float('inf')]*n [0]+[-float('inf')]*n dp
n,m = map(int,input().split())
a = set(map(int,input().split()))
dp = [0]+[-float('inf')]*n
f = [0,2,5,5,4,5,6,3,7,6]
for i in range(n+1):
  for j in a:
    F = f[j]
    if F <= i:
      dp[i] = max(dp[i-F]*10+j,dp[i])
print(dp[n])