N, M = map(int, input().split())
A = list(map(int, input().split()))

tab = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
A_cmp = {}
for Ai in sorted(A):
    A_cmp[tab[Ai]] = Ai
A = list(A_cmp.values())
A.sort(key=lambda x: -x)

memo = [None] * (N + 1)
memo[0] = 0

import sys
sys.setrecursionlimit(100000)

def dp(X):
    if X < 0: return -(1000000007)
    if memo[X] != None: return memo[X]
    #
    rets = []
    for i, Ai in enumerate(A):
        rets.append(dp(X - tab[Ai]) + 1)
    #
    ret = max(rets)
    memo[X] = ret
    return ret

ans_len = dp(N)

N_tmp = N
ans = ''
for i in range(ans_len):
    for j, Aj in enumerate(A):
        if dp(N_tmp) - 1 == dp(N_tmp - tab[Aj]):
            ans += str(Aj)
            N_tmp -= tab[Aj]
            break

print(ans) 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 tab = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6] tab [6, 2, 5, 5, 4, 5, 6, 3, 7, 6] 6 2 5 5 4 5 6 3 7 6 A_cmp = {} A_cmp {} for Ai in sorted(A):
    A_cmp[tab[Ai]] = Ai Ai sorted(A) sorted A A_cmp[tab[Ai]] = Ai A_cmp[tab[Ai]] A_cmp tab[Ai] tab Ai Ai A = list(A_cmp.values()) A list(A_cmp.values()) list A_cmp.values() A_cmp.values A_cmp values A.sort(key=lambda x: -x) A.sort A sort key=lambda x: -x key lambda x: -x -x x x memo = [None] * (N + 1) memo [None] * (N + 1) [None] None N + 1 N 1 memo[0] = 0 memo[0] memo 0 0 import sys sys sys.setrecursionlimit(100000) sys.setrecursionlimit sys setrecursionlimit 100000 def dp(X):
    if X < 0: return -(1000000007)
    if memo[X] != None: return memo[X]
    #
    rets = []
    for i, Ai in enumerate(A):
        rets.append(dp(X - tab[Ai]) + 1)
    #
    ret = max(rets)
    memo[X] = ret
    return ret dp if X < 0: return -(1000000007)
     X < 0 X 0 if memo[X] != None: return memo[X]
    #
     memo[X] != None memo[X] memo X None rets = [] rets [] for i, Ai in enumerate(A):
        rets.append(dp(X - tab[Ai]) + 1)
    #
     i Ai enumerate(A) enumerate A rets.append(dp(X - tab[Ai]) + 1) rets.append rets append dp(X - tab[Ai]) + 1 dp(X - tab[Ai]) dp X - tab[Ai] X tab[Ai] tab Ai 1 ret = max(rets) ret max(rets) max rets memo[X] = ret memo[X] memo X ret return ret ret X X ans_len = dp(N) ans_len dp(N) dp N N_tmp = N N_tmp N ans = '' ans '' for i in range(ans_len):
    for j, Aj in enumerate(A):
        if dp(N_tmp) - 1 == dp(N_tmp - tab[Aj]):
            ans += str(Aj)
            N_tmp -= tab[Aj]
            break i range(ans_len) range ans_len for j, Aj in enumerate(A):
        if dp(N_tmp) - 1 == dp(N_tmp - tab[Aj]):
            ans += str(Aj)
            N_tmp -= tab[Aj]
            break j Aj enumerate(A) enumerate A if dp(N_tmp) - 1 == dp(N_tmp - tab[Aj]):
            ans += str(Aj)
            N_tmp -= tab[Aj]
            break dp(N_tmp) - 1 == dp(N_tmp - tab[Aj]) dp(N_tmp) - 1 dp(N_tmp) dp N_tmp 1 dp(N_tmp - tab[Aj]) dp N_tmp - tab[Aj] N_tmp tab[Aj] tab Aj ans += str(Aj) ans str(Aj) str Aj N_tmp -= tab[Aj] N_tmp tab[Aj] tab Aj break print(ans) print ans N, M = map(int, input().split()) map(int, input().split()) N A = list(map(int, input().split())) list(map(int, input().split())) A A_cmp = {} {} A_cmp ans_len = dp(N) dp(N) ans_len N_tmp = N N N_tmp def dp(X):
    if X < 0: return -(1000000007)
    if memo[X] != None: return memo[X]
    #
    rets = []
    for i, Ai in enumerate(A):
        rets.append(dp(X - tab[Ai]) + 1)
    #
    ret = max(rets)
    memo[X] = ret
    return ret def dp(X):
    if X < 0: return -(1000000007)
    if memo[X] != None: return memo[X]
    #
    rets = []
    for i, Ai in enumerate(A):
        rets.append(dp(X - tab[Ai]) + 1)
    #
    ret = max(rets)
    memo[X] = ret
    return ret dp N_tmp -= tab[Aj] tab[Aj] N_tmp M = map(int, input().split()) map(int, input().split()) M ans += str(Aj) str(Aj) ans tab = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6] [6, 2, 5, 5, 4, 5, 6, 3, 7, 6] tab A = list(A_cmp.values()) list(A_cmp.values()) A memo = [None] * (N + 1) [None] * (N + 1) memo ans = '' '' ans
N, M = map(int, input().split())
A = list(map(int, input().split()))

tab = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
A_cmp = {}
for Ai in sorted(A):
    A_cmp[tab[Ai]] = Ai
A = list(A_cmp.values())
A.sort(key=lambda x: -x)

memo = [None] * (N + 1)
memo[0] = 0

import sys
sys.setrecursionlimit(100000)

def dp(X):
    if X < 0: return -(1000000007)
    if memo[X] != None: return memo[X]
    #
    rets = []
    for i, Ai in enumerate(A):
        rets.append(dp(X - tab[Ai]) + 1)
    #
    ret = max(rets)
    memo[X] = ret
    return ret

ans_len = dp(N)

N_tmp = N
ans = ''
for i in range(ans_len):
    for j, Aj in enumerate(A):
        if dp(N_tmp) - 1 == dp(N_tmp - tab[Aj]):
            ans += str(Aj)
            N_tmp -= tab[Aj]
            break

print(ans)