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

x = [-float('inf')] * (n + 1)
x[0] = 0
l = [0] * (n + 1)
_c = [2,5,5,4,5,6,3,7,6]
c = dict()
for i in range(m):
    c[a[i]] = _c[a[i] - 1]

for i in range(1, n + 1):
    x_max = -float('inf')
    l_max = 0
    for digit in c.keys():
        left = i - c[digit]
        if left >= 0:
            tmp_x = digit * (10 ** l[left]) + x[left]
            tmp_l = l[left] + 1
            if tmp_x > x_max:
                x_max = tmp_x
                l_max = tmp_l

    x[i] = x_max
    l[i] = l_max
print(x[-1]) n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m a = list(map(int, input().split())) a list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split x = [-float('inf')] * (n + 1) x [-float('inf')] * (n + 1) [-float('inf')] -float('inf') float('inf') float 'inf' n + 1 n 1 x[0] = 0 x[0] x 0 0 l = [0] * (n + 1) l [0] * (n + 1) [0] 0 n + 1 n 1 _c = [2,5,5,4,5,6,3,7,6] _c [2,5,5,4,5,6,3,7,6] 2 5 5 4 5 6 3 7 6 c = dict() c dict() dict for i in range(m):
    c[a[i]] = _c[a[i] - 1] i range(m) range m c[a[i]] = _c[a[i] - 1] c[a[i]] c a[i] a i _c[a[i] - 1] _c a[i] - 1 a[i] a i 1 for i in range(1, n + 1):
    x_max = -float('inf')
    l_max = 0
    for digit in c.keys():
        left = i - c[digit]
        if left >= 0:
            tmp_x = digit * (10 ** l[left]) + x[left]
            tmp_l = l[left] + 1
            if tmp_x > x_max:
                x_max = tmp_x
                l_max = tmp_l

    x[i] = x_max
    l[i] = l_max i range(1, n + 1) range 1 n + 1 n 1 x_max = -float('inf') x_max -float('inf') float('inf') float 'inf' l_max = 0 l_max 0 for digit in c.keys():
        left = i - c[digit]
        if left >= 0:
            tmp_x = digit * (10 ** l[left]) + x[left]
            tmp_l = l[left] + 1
            if tmp_x > x_max:
                x_max = tmp_x
                l_max = tmp_l

     digit c.keys() c.keys c keys left = i - c[digit] left i - c[digit] i c[digit] c digit if left >= 0:
            tmp_x = digit * (10 ** l[left]) + x[left]
            tmp_l = l[left] + 1
            if tmp_x > x_max:
                x_max = tmp_x
                l_max = tmp_l

     left >= 0 left 0 tmp_x = digit * (10 ** l[left]) + x[left] tmp_x digit * (10 ** l[left]) + x[left] digit * (10 ** l[left]) digit 10 ** l[left] 10 l[left] l left x[left] x left tmp_l = l[left] + 1 tmp_l l[left] + 1 l[left] l left 1 if tmp_x > x_max:
                x_max = tmp_x
                l_max = tmp_l

     tmp_x > x_max tmp_x x_max x_max = tmp_x x_max tmp_x l_max = tmp_l l_max tmp_l x[i] = x_max x[i] x i x_max l[i] = l_max l[i] l i l_max print(x[-1]) print x[-1] x -1 x = [-float('inf')] * (n + 1) [-float('inf')] * (n + 1) x x_max = tmp_x tmp_x x_max m = map(int, input().split()) map(int, input().split()) m c = dict() dict() c l = [0] * (n + 1) [0] * (n + 1) l _c = [2,5,5,4,5,6,3,7,6] [2,5,5,4,5,6,3,7,6] _c n, m = map(int, input().split()) map(int, input().split()) n tmp_l = l[left] + 1 l[left] + 1 tmp_l a = list(map(int, input().split())) list(map(int, input().split())) a tmp_x = digit * (10 ** l[left]) + x[left] digit * (10 ** l[left]) + x[left] tmp_x x_max = -float('inf') -float('inf') x_max l_max = 0 0 l_max left = i - c[digit] i - c[digit] left l_max = tmp_l tmp_l l_max
n, m = map(int, input().split())
a = list(map(int, input().split()))

x = [-float('inf')] * (n + 1)
x[0] = 0
l = [0] * (n + 1)
_c = [2,5,5,4,5,6,3,7,6]
c = dict()
for i in range(m):
    c[a[i]] = _c[a[i] - 1]

for i in range(1, n + 1):
    x_max = -float('inf')
    l_max = 0
    for digit in c.keys():
        left = i - c[digit]
        if left >= 0:
            tmp_x = digit * (10 ** l[left]) + x[left]
            tmp_l = l[left] + 1
            if tmp_x > x_max:
                x_max = tmp_x
                l_max = tmp_l

    x[i] = x_max
    l[i] = l_max
print(x[-1])
