import sys
import copy

sys.setrecursionlimit(10**6)

m = [0,2,5,5,4,5,6,3,7,6]

def a_le_b(a, b):
    la, lb = len(a), len(b)
    if la == lb:
        for i in range(la):
            if a[i] < b[i]:
                return True
            elif a[i] > b[i]:
                return False
        return True
    return la < lb

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
for i in range(len(A)-1, 0, -1):
    for j in range(i-1, -1, -1):
        if m[A[i]] == m[A[j]]:
            del A[i]
            break
# print(A)
dp = [[] for _ in range(N+1)]

for i in range(N):
    if len(dp[i])==0 and i != 0: continue
    x = copy.copy(dp[i]) + [0]
    # print(x)
    for j in range(len(A)):
        ind = i + m[A[j]]
        if ind <= N:
            x[-1] = A[j]
            if a_le_b(dp[ind], x):
                dp[ind] = copy.copy(x)
# print(dp)
print(''.join(map(str, dp[-1]))) import sys sys import copy copy sys.setrecursionlimit(10**6) sys.setrecursionlimit sys setrecursionlimit 10**6 10 6 m = [0,2,5,5,4,5,6,3,7,6] m [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 def a_le_b(a, b):
    la, lb = len(a), len(b)
    if la == lb:
        for i in range(la):
            if a[i] < b[i]:
                return True
            elif a[i] > b[i]:
                return False
        return True
    return la < lb a_le_b la, lb = len(a), len(b) la len(a) len a lb len(b) len b if la == lb:
        for i in range(la):
            if a[i] < b[i]:
                return True
            elif a[i] > b[i]:
                return False
        return True
     la == lb la lb for i in range(la):
            if a[i] < b[i]:
                return True
            elif a[i] > b[i]:
                return False
         i range(la) range la if a[i] < b[i]:
                return True
            elif a[i] > b[i]:
                return False
         a[i] < b[i] a[i] a i b[i] b i return True True elif a[i] > b[i]:
                return False
         a[i] > b[i] a[i] a i b[i] b i return False False return True True return la < lb la < lb la lb a a b b 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 A.sort(reverse=True) A.sort A sort reverse=True reverse True for i in range(len(A)-1, 0, -1):
    for j in range(i-1, -1, -1):
        if m[A[i]] == m[A[j]]:
            del A[i]
            break
# print(A) i range(len(A)-1, 0, -1) range len(A)-1 len(A) len A 1 0 -1 for j in range(i-1, -1, -1):
        if m[A[i]] == m[A[j]]:
            del A[i]
            break
# print(A) j range(i-1, -1, -1) range i-1 i 1 -1 -1 if m[A[i]] == m[A[j]]:
            del A[i]
            break
# print(A) m[A[i]] == m[A[j]] m[A[i]] m A[i] A i m[A[j]] m A[j] A j del A[i] A[i] A i break [] for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) [] dp = [[] for _ in range(N+1)] dp [[] for _ in range(N+1)] for i in range(N):
    if len(dp[i])==0 and i != 0: continue
    x = copy.copy(dp[i]) + [0]
    # print(x)
    for j in range(len(A)):
        ind = i + m[A[j]]
        if ind <= N:
            x[-1] = A[j]
            if a_le_b(dp[ind], x):
                dp[ind] = copy.copy(x)
# print(dp) i range(N) range N if len(dp[i])==0 and i != 0: continue
     len(dp[i])==0 and i != 0 len(dp[i])==0 len(dp[i]) len dp[i] dp i 0 i != 0 i 0 x = copy.copy(dp[i]) + [0] x copy.copy(dp[i]) + [0] copy.copy(dp[i]) copy.copy copy copy dp[i] dp i [0] 0 for j in range(len(A)):
        ind = i + m[A[j]]
        if ind <= N:
            x[-1] = A[j]
            if a_le_b(dp[ind], x):
                dp[ind] = copy.copy(x)
# print(dp) j range(len(A)) range len(A) len A ind = i + m[A[j]] ind i + m[A[j]] i m[A[j]] m A[j] A j if ind <= N:
            x[-1] = A[j]
            if a_le_b(dp[ind], x):
                dp[ind] = copy.copy(x)
# print(dp) ind <= N ind N x[-1] = A[j] x[-1] x -1 A[j] A j if a_le_b(dp[ind], x):
                dp[ind] = copy.copy(x)
# print(dp) a_le_b(dp[ind], x) a_le_b dp[ind] dp ind x dp[ind] = copy.copy(x) dp[ind] dp ind copy.copy(x) copy.copy copy copy x print(''.join(map(str, dp[-1]))) print ''.join(map(str, dp[-1])) ''.join '' join map(str, dp[-1]) map str dp[-1] dp -1 def a_le_b(a, b):
    la, lb = len(a), len(b)
    if la == lb:
        for i in range(la):
            if a[i] < b[i]:
                return True
            elif a[i] > b[i]:
                return False
        return True
    return la < lb def a_le_b(a, b):
    la, lb = len(a), len(b)
    if la == lb:
        for i in range(la):
            if a[i] < b[i]:
                return True
            elif a[i] > b[i]:
                return False
        return True
    return la < lb a_le_b N, M = map(int, input().split()) map(int, input().split()) N A = list(map(int, input().split())) list(map(int, input().split())) A ind = i + m[A[j]] i + m[A[j]] ind m = [0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] m M = map(int, input().split()) map(int, input().split()) M dp = [[] for _ in range(N+1)] [[] for _ in range(N+1)] dp x = copy.copy(dp[i]) + [0] copy.copy(dp[i]) + [0] x
import sys
import copy

sys.setrecursionlimit(10**6)

m = [0,2,5,5,4,5,6,3,7,6]

def a_le_b(a, b):
    la, lb = len(a), len(b)
    if la == lb:
        for i in range(la):
            if a[i] < b[i]:
                return True
            elif a[i] > b[i]:
                return False
        return True
    return la < lb

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
for i in range(len(A)-1, 0, -1):
    for j in range(i-1, -1, -1):
        if m[A[i]] == m[A[j]]:
            del A[i]
            break
# print(A)
dp = [[] for _ in range(N+1)]

for i in range(N):
    if len(dp[i])==0 and i != 0: continue
    x = copy.copy(dp[i]) + [0]
    # print(x)
    for j in range(len(A)):
        ind = i + m[A[j]]
        if ind <= N:
            x[-1] = A[j]
            if a_le_b(dp[ind], x):
                dp[ind] = copy.copy(x)
# print(dp)
print(''.join(map(str, dp[-1])))
