from collections import defaultdict as dd



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

*a,=list(map(int,input().split()))

dp=[-1]*(n+1)

ans = [0] * (n + 1)



cost={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}



d={i:cost[i] for i in a}



dp[0] = 0

for i in range(1,n+1):

    for j in range(10)[::-1]:

        if not j in d:

            continue

        if cost[j] > i:

            continue

        if dp[i] < dp[i - cost[j]] + 1:

            dp[i] = dp[i - cost[j]] + 1

            ans[i] = j



S = ""

pos = n



while pos != 0:

    S += str(ans[pos])

    pos -= cost[ans[pos]]



print(S)

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

*a,=map(int,input().split())



cost={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}

dp=[-1]*(n+1)

v=[0]*(n+1)



dp[0]=0

for i in range(1,n+1):

    for j in range(10)[::-1]:

        if not j in a or i<cost[j]:continue

        if dp[i]<dp[i-cost[j]]+1:

            dp[i]=dp[i-cost[j]]+1

            v[i]=j



p=n

while p!=0:

    print(v[p],end="")

    p-=cost[v[p]]

print()

from collections import defaultdict as dd

n, m = list(map(int, input().split()))
(*a,) = list(map(int, input().split()))
dp = [-1] * (n + 1)
ans = [0] * (n + 1)
cost = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
d = {i: cost[i] for i in a}
dp[0] = 0
for i in range(1, n + 1):
    for j in range(10)[::-1]:
        if not j in d:
            continue
        if cost[j] > i:
            continue
        if dp[i] < dp[i - cost[j]] + 1:
            dp[i] = dp[i - cost[j]] + 1
            ans[i] = j
S = ""
pos = n
while pos != 0:
    S += str(ans[pos])
    pos -= cost[ans[pos]]
print(S)

n, m = map(int, input().split())
(*a,) = map(int, input().split())
cost = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
dp = [-1] * (n + 1)
v = [0] * (n + 1)
dp[0] = 0
for i in range(1, n + 1):
    for j in range(10)[::-1]:
        if not j in a or i < cost[j]:
            continue
        if dp[i] < dp[i - cost[j]] + 1:
            dp[i] = dp[i - cost[j]] + 1
            v[i] = j
p = n
while p != 0:
    print(v[p], end="")
    p -= cost[v[p]]
print()

-from collections import defaultdict as dd - -n, m = list(map(int, input().split())) -(*a,) = list(map(int, input().split())) +n, m = map(int, input().split()) +(*a,) = map(int, input().split()) +cost = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6} -ans = [0] * (n + 1) -cost = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6} -d = {i: cost[i] for i in a} +v = [0] * (n + 1) -        if not j in d: -            continue -        if cost[j] > i: +        if not j in a or i < cost[j]: -            ans[i] = j -S = "" -pos = n -while pos != 0: -    S += str(ans[pos]) -    pos -= cost[ans[pos]] -print(S) +            v[i] = j +p = n +while p != 0: +    print(v[p], end="") +    p -= cost[v[p]] +print()