n,m = map(int, input().split())

a = [int(i) for i in input().split()]

l = [0,2,5,5,4,5,6,3,7,6]
inf = float("INF")
dp = [-inf] * (n+10)
d = [-inf] * (n+10)
dp[0] = 0
d[0] = 0
for i in range(n):
  if dp[i] == -inf: continue
  tmp = dp[i]
  k = d[i]
  for ai in a:
    dp[l[ai] + i] = max(dp[l[ai] + i], dp[i] + k * ai, dp[i] * 10 + ai)
    d[i + l[ai]] = max(d[i + l[ai]], k + 1)
print(dp[n]) n,m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i a = [int(i) for i in input().split()] a [int(i) for i in input().split()] l = [0,2,5,5,4,5,6,3,7,6] l [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 inf = float("INF") inf float("INF") float "INF" dp = [-inf] * (n+10) dp [-inf] * (n+10) [-inf] -inf inf n+10 n 10 d = [-inf] * (n+10) d [-inf] * (n+10) [-inf] -inf inf n+10 n 10 dp[0] = 0 dp[0] dp 0 0 d[0] = 0 d[0] d 0 0 for i in range(n):
  if dp[i] == -inf: continue
  tmp = dp[i]
  k = d[i]
  for ai in a:
    dp[l[ai] + i] = max(dp[l[ai] + i], dp[i] + k * ai, dp[i] * 10 + ai)
    d[i + l[ai]] = max(d[i + l[ai]], k + 1) i range(n) range n if dp[i] == -inf: continue
   dp[i] == -inf dp[i] dp i -inf inf tmp = dp[i] tmp dp[i] dp i k = d[i] k d[i] d i for ai in a:
    dp[l[ai] + i] = max(dp[l[ai] + i], dp[i] + k * ai, dp[i] * 10 + ai)
    d[i + l[ai]] = max(d[i + l[ai]], k + 1) ai a dp[l[ai] + i] = max(dp[l[ai] + i], dp[i] + k * ai, dp[i] * 10 + ai) dp[l[ai] + i] dp l[ai] + i l[ai] l ai i max(dp[l[ai] + i], dp[i] + k * ai, dp[i] * 10 + ai) max dp[l[ai] + i] dp l[ai] + i l[ai] l ai i dp[i] + k * ai dp[i] dp i k * ai k ai dp[i] * 10 + ai dp[i] * 10 dp[i] dp i 10 ai d[i + l[ai]] = max(d[i + l[ai]], k + 1) d[i + l[ai]] d i + l[ai] i l[ai] l ai max(d[i + l[ai]], k + 1) max d[i + l[ai]] d i + l[ai] i l[ai] l ai k + 1 k 1 print(dp[n]) print dp[n] dp n m = map(int, input().split()) map(int, input().split()) m a = [int(i) for i in input().split()] [int(i) for i in input().split()] a inf = float("INF") float("INF") inf l = [0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] l tmp = dp[i] dp[i] tmp k = d[i] d[i] k dp = [-inf] * (n+10) [-inf] * (n+10) dp n,m = map(int, input().split()) map(int, input().split()) n d = [-inf] * (n+10) [-inf] * (n+10) d
n,m = map(int, input().split())

a = [int(i) for i in input().split()]

l = [0,2,5,5,4,5,6,3,7,6]
inf = float("INF")
dp = [-inf] * (n+10)
d = [-inf] * (n+10)
dp[0] = 0
d[0] = 0
for i in range(n):
  if dp[i] == -inf: continue
  tmp = dp[i]
  k = d[i]
  for ai in a:
    dp[l[ai] + i] = max(dp[l[ai] + i], dp[i] + k * ai, dp[i] * 10 + ai)
    d[i + l[ai]] = max(d[i + l[ai]], k + 1)
print(dp[n])
