import sys
sys.setrecursionlimit(10 ** 5)
lst = [[1,2], [2, 5], [3, 5], [4, 4], [5, 5], [6, 6], [7, 3], [8, 7], [9, 6]]
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse = True)
# print (A)

def num(k):
    return lst[k-1][1]

# for i in A:
    # print (num(i), end = ', ')
# print ()

INF = 10 ** 5
dp_lst = [-INF] * (N + 1)
dp_lst[0] = 0
def dp(i):
    if dp_lst[i] != -INF:
        return dp_lst[i]
    tmp = -INF
    for j in A:
        if i >= num(j):
            tmp = max(tmp, dp(i - num(j)) + 1)
    dp_lst[i] = tmp
    return dp_lst[i]

a = dp(N)
# print (a)
# print (dp_lst)   
# print ([0] * 10 +[i+1 for i in range(20)])

# print (len(str(71111111111111111111111111111111111111111111111111)))

def check(A):
    if N - num(A) < 0:
        return False
    if dp_lst[N-num(A)] == dp_lst[N] - 1:
        return True
    else:
        return False

# print (a)
while a > 0:
    for i in A:
        if check(i):
            print (i, end = '')
            N -= num(i)
            a -= 1
            break
        else:
            pass
            # print ('B')
print () import sys sys sys.setrecursionlimit(10 ** 5) sys.setrecursionlimit sys setrecursionlimit 10 ** 5 10 5 lst = [[1,2], [2, 5], [3, 5], [4, 4], [5, 5], [6, 6], [7, 3], [8, 7], [9, 6]] lst [[1,2], [2, 5], [3, 5], [4, 4], [5, 5], [6, 6], [7, 3], [8, 7], [9, 6]] [1,2] 1 2 [2, 5] 2 5 [3, 5] 3 5 [4, 4] 4 4 [5, 5] 5 5 [6, 6] 6 6 [7, 3] 7 3 [8, 7] 8 7 [9, 6] 9 6 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 def num(k):
    return lst[k-1][1]

# for i in A:
    # print (num(i), end = ', ')
# print () num return lst[k-1][1] lst[k-1][1] [k-1] lst k-1 k 1 1 k k INF = 10 ** 5 INF 10 ** 5 10 5 dp_lst = [-INF] * (N + 1) dp_lst [-INF] * (N + 1) [-INF] -INF INF N + 1 N 1 dp_lst[0] = 0 dp_lst[0] dp_lst 0 0 def dp(i):
    if dp_lst[i] != -INF:
        return dp_lst[i]
    tmp = -INF
    for j in A:
        if i >= num(j):
            tmp = max(tmp, dp(i - num(j)) + 1)
    dp_lst[i] = tmp
    return dp_lst[i] dp if dp_lst[i] != -INF:
        return dp_lst[i]
     dp_lst[i] != -INF dp_lst[i] dp_lst i -INF INF return dp_lst[i] dp_lst[i] dp_lst i tmp = -INF tmp -INF INF for j in A:
        if i >= num(j):
            tmp = max(tmp, dp(i - num(j)) + 1)
     j A if i >= num(j):
            tmp = max(tmp, dp(i - num(j)) + 1)
     i >= num(j) i num(j) num j tmp = max(tmp, dp(i - num(j)) + 1) tmp max(tmp, dp(i - num(j)) + 1) max tmp dp(i - num(j)) + 1 dp(i - num(j)) dp i - num(j) i num(j) num j 1 dp_lst[i] = tmp dp_lst[i] dp_lst i tmp return dp_lst[i] dp_lst[i] dp_lst i i i a = dp(N) a dp(N) dp N def check(A):
    if N - num(A) < 0:
        return False
    if dp_lst[N-num(A)] == dp_lst[N] - 1:
        return True
    else:
        return False

# print (a) check if N - num(A) < 0:
        return False
     N - num(A) < 0 N - num(A) N num(A) num A 0 return False False if dp_lst[N-num(A)] == dp_lst[N] - 1:
        return True
    else:
        return False

# print (a) dp_lst[N-num(A)] == dp_lst[N] - 1 dp_lst[N-num(A)] dp_lst N-num(A) N num(A) num A dp_lst[N] - 1 dp_lst[N] dp_lst N 1 return True True return False False A A while a > 0:
    for i in A:
        if check(i):
            print (i, end = '')
            N -= num(i)
            a -= 1
            break
        else:
            pass
            # print ('B') a > 0 a 0 for i in A:
        if check(i):
            print (i, end = '')
            N -= num(i)
            a -= 1
            break
        else:
            pass
            # print ('B') i A if check(i):
            print (i, end = '')
            N -= num(i)
            a -= 1
            break
        else:
            pass
            # print ('B') check(i) check i print (i, end = '') print i end = '' end '' N -= num(i) N num(i) num i a -= 1 a 1 break print () print M = map(int, input().split()) map(int, input().split()) M lst = [[1,2], [2, 5], [3, 5], [4, 4], [5, 5], [6, 6], [7, 3], [8, 7], [9, 6]] [[1,2], [2, 5], [3, 5], [4, 4], [5, 5], [6, 6], [7, 3], [8, 7], [9, 6]] lst def check(A):
    if N - num(A) < 0:
        return False
    if dp_lst[N-num(A)] == dp_lst[N] - 1:
        return True
    else:
        return False

# print (a) def check(A):
    if N - num(A) < 0:
        return False
    if dp_lst[N-num(A)] == dp_lst[N] - 1:
        return True
    else:
        return False

# print (a) check N -= num(i) num(i) N a -= 1 1 a N, M = map(int, input().split()) map(int, input().split()) N INF = 10 ** 5 10 ** 5 INF a = dp(N) dp(N) a def dp(i):
    if dp_lst[i] != -INF:
        return dp_lst[i]
    tmp = -INF
    for j in A:
        if i >= num(j):
            tmp = max(tmp, dp(i - num(j)) + 1)
    dp_lst[i] = tmp
    return dp_lst[i] def dp(i):
    if dp_lst[i] != -INF:
        return dp_lst[i]
    tmp = -INF
    for j in A:
        if i >= num(j):
            tmp = max(tmp, dp(i - num(j)) + 1)
    dp_lst[i] = tmp
    return dp_lst[i] dp A = list(map(int, input().split())) list(map(int, input().split())) A def num(k):
    return lst[k-1][1]

# for i in A:
    # print (num(i), end = ', ')
# print () def num(k):
    return lst[k-1][1]

# for i in A:
    # print (num(i), end = ', ')
# print () num dp_lst = [-INF] * (N + 1) [-INF] * (N + 1) dp_lst
import sys
sys.setrecursionlimit(10 ** 5)
lst = [[1,2], [2, 5], [3, 5], [4, 4], [5, 5], [6, 6], [7, 3], [8, 7], [9, 6]]
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse = True)
# print (A)

def num(k):
    return lst[k-1][1]

# for i in A:
    # print (num(i), end = ', ')
# print ()

INF = 10 ** 5
dp_lst = [-INF] * (N + 1)
dp_lst[0] = 0
def dp(i):
    if dp_lst[i] != -INF:
        return dp_lst[i]
    tmp = -INF
    for j in A:
        if i >= num(j):
            tmp = max(tmp, dp(i - num(j)) + 1)
    dp_lst[i] = tmp
    return dp_lst[i]

a = dp(N)
# print (a)
# print (dp_lst)   
# print ([0] * 10 +[i+1 for i in range(20)])

# print (len(str(71111111111111111111111111111111111111111111111111)))

def check(A):
    if N - num(A) < 0:
        return False
    if dp_lst[N-num(A)] == dp_lst[N] - 1:
        return True
    else:
        return False

# print (a)
while a > 0:
    for i in A:
        if check(i):
            print (i, end = '')
            N -= num(i)
            a -= 1
            break
        else:
            pass
            # print ('B')
print ()