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

num_of_matches = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = ['x'] * (n+8)
dp[0] = ''
for i in range(n+1):
    if dp[i] == 'x':
        continue
    for aa in a:
        x = dp[i + num_of_matches[aa]]
        y = dp[i] + str(aa)
        if x == 'x':
            dp[i + num_of_matches[aa]] = y
        elif len(x) < len(y):
            dp[i + num_of_matches[aa]] = y
        elif len(x) == len(y):
            if x < y:
                dp[i + num_of_matches[aa]] = y
print(dp[n]) 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 num_of_matches = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6] num_of_matches [6, 2, 5, 5, 4, 5, 6, 3, 7, 6] 6 2 5 5 4 5 6 3 7 6 dp = ['x'] * (n+8) dp ['x'] * (n+8) ['x'] 'x' n+8 n 8 dp[0] = '' dp[0] dp 0 '' for i in range(n+1):
    if dp[i] == 'x':
        continue
    for aa in a:
        x = dp[i + num_of_matches[aa]]
        y = dp[i] + str(aa)
        if x == 'x':
            dp[i + num_of_matches[aa]] = y
        elif len(x) < len(y):
            dp[i + num_of_matches[aa]] = y
        elif len(x) == len(y):
            if x < y:
                dp[i + num_of_matches[aa]] = y i range(n+1) range n+1 n 1 if dp[i] == 'x':
        continue
     dp[i] == 'x' dp[i] dp i 'x' continue for aa in a:
        x = dp[i + num_of_matches[aa]]
        y = dp[i] + str(aa)
        if x == 'x':
            dp[i + num_of_matches[aa]] = y
        elif len(x) < len(y):
            dp[i + num_of_matches[aa]] = y
        elif len(x) == len(y):
            if x < y:
                dp[i + num_of_matches[aa]] = y aa a x = dp[i + num_of_matches[aa]] x dp[i + num_of_matches[aa]] dp i + num_of_matches[aa] i num_of_matches[aa] num_of_matches aa y = dp[i] + str(aa) y dp[i] + str(aa) dp[i] dp i str(aa) str aa if x == 'x':
            dp[i + num_of_matches[aa]] = y
        elif len(x) < len(y):
            dp[i + num_of_matches[aa]] = y
        elif len(x) == len(y):
            if x < y:
                dp[i + num_of_matches[aa]] = y x == 'x' x 'x' dp[i + num_of_matches[aa]] = y dp[i + num_of_matches[aa]] dp i + num_of_matches[aa] i num_of_matches[aa] num_of_matches aa y elif len(x) < len(y):
            dp[i + num_of_matches[aa]] = y
         len(x) < len(y) len(x) len x len(y) len y dp[i + num_of_matches[aa]] = y dp[i + num_of_matches[aa]] dp i + num_of_matches[aa] i num_of_matches[aa] num_of_matches aa y elif len(x) == len(y):
            if x < y:
                dp[i + num_of_matches[aa]] = y len(x) == len(y) len(x) len x len(y) len y if x < y:
                dp[i + num_of_matches[aa]] = y x < y x y dp[i + num_of_matches[aa]] = y dp[i + num_of_matches[aa]] dp i + num_of_matches[aa] i num_of_matches[aa] num_of_matches aa y print(dp[n]) print dp[n] dp n dp = ['x'] * (n+8) ['x'] * (n+8) dp y = dp[i] + str(aa) dp[i] + str(aa) y num_of_matches = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6] [6, 2, 5, 5, 4, 5, 6, 3, 7, 6] num_of_matches x = dp[i + num_of_matches[aa]] dp[i + num_of_matches[aa]] x m = map(int, input().split()) map(int, input().split()) m n, m = map(int, input().split()) map(int, input().split()) n a = list(map(int, input().split())) list(map(int, input().split())) a
n, m = map(int, input().split())
a = list(map(int, input().split()))

num_of_matches = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = ['x'] * (n+8)
dp[0] = ''
for i in range(n+1):
    if dp[i] == 'x':
        continue
    for aa in a:
        x = dp[i + num_of_matches[aa]]
        y = dp[i] + str(aa)
        if x == 'x':
            dp[i + num_of_matches[aa]] = y
        elif len(x) < len(y):
            dp[i + num_of_matches[aa]] = y
        elif len(x) == len(y):
            if x < y:
                dp[i + num_of_matches[aa]] = y
print(dp[n])
