def examA():
    A, B = LI()
    if B%A==0:
        ans = A+B
    else:
        ans = B-A
    print(ans)
    return

def examB():
    N, M = LI()
    Flag = [0]*M
    for i in range(N):
        K = LI()
        for j in range(1,K[0]+1):
            Flag[K[j]-1] +=1
    ans = 0
    for i in Flag:
        if i==N:
            ans +=1
    print(ans)
    return

def gcd(x,y):
    if y==0:
        return x
    while(y!=0):
        x, y = y,x%y
    return x
def examC():
    N = I()
    A = LI()
    cur = A[0]
    for i in range(N-1):
        cur = gcd(cur,A[i+1])
    ans = cur
    print(ans)
    return

def examD():
    N, M = LI()
    A = LI(); A.sort()
    Matti = [2,5,5,4,5,6,3,7,6]
    D = {}
    for a in A:
        D[Matti[a-1]] = a
    D = sorted(D.items())
    #print(D)
    dp = [-inf]*(N+10)
    dp[0] = 0
    for i in range(N):
        for matti,num in D:
            dp[i+matti] = max(dp[i+matti],dp[i]+1)
    #print(dp[:N+1])
    D = sorted(D, key=lambda x: x[1], reverse=True)
    #print(D)
    used = []
    i = N
    for matti,num in D:
        while (i > 0):
            # print(i)
            # input()
            #print(i,matti,used)
            if i-matti<0:
                break
            if dp[i-matti]==dp[i]-1:
                used.append(num)
                i -= matti
            else:
                break
    #print(used)
    used.sort(reverse=True)
    ans = "".join(map(str,used))
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examD()


"""
31 2
5 8
""" def examA():
    A, B = LI()
    if B%A==0:
        ans = A+B
    else:
        ans = B-A
    print(ans)
    return examA A, B = LI() A LI() LI B if B%A==0:
        ans = A+B
    else:
        ans = B-A
     B%A==0 B%A B A 0 ans = A+B ans A+B A B ans = B-A ans B-A B A print(ans) print ans return def examB():
    N, M = LI()
    Flag = [0]*M
    for i in range(N):
        K = LI()
        for j in range(1,K[0]+1):
            Flag[K[j]-1] +=1
    ans = 0
    for i in Flag:
        if i==N:
            ans +=1
    print(ans)
    return examB N, M = LI() N LI() LI M Flag = [0]*M Flag [0]*M [0] 0 M for i in range(N):
        K = LI()
        for j in range(1,K[0]+1):
            Flag[K[j]-1] +=1
     i range(N) range N K = LI() K LI() LI for j in range(1,K[0]+1):
            Flag[K[j]-1] +=1
     j range(1,K[0]+1) range 1 K[0]+1 K[0] K 0 1 Flag[K[j]-1] +=1 Flag[K[j]-1] Flag K[j]-1 K[j] K j 1 1 ans = 0 ans 0 for i in Flag:
        if i==N:
            ans +=1
     i Flag if i==N:
            ans +=1
     i==N i N ans +=1 ans 1 print(ans) print ans return def gcd(x,y):
    if y==0:
        return x
    while(y!=0):
        x, y = y,x%y
    return x gcd if y==0:
        return x
     y==0 y 0 return x x while(y!=0):
        x, y = y,x%y
     y!=0 y 0 x, y = y,x%y x y y x%y x y return x x x x y y def examC():
    N = I()
    A = LI()
    cur = A[0]
    for i in range(N-1):
        cur = gcd(cur,A[i+1])
    ans = cur
    print(ans)
    return examC N = I() N I() I A = LI() A LI() LI cur = A[0] cur A[0] A 0 for i in range(N-1):
        cur = gcd(cur,A[i+1])
     i range(N-1) range N-1 N 1 cur = gcd(cur,A[i+1]) cur gcd(cur,A[i+1]) gcd cur A[i+1] A i+1 i 1 ans = cur ans cur print(ans) print ans return def examD():
    N, M = LI()
    A = LI(); A.sort()
    Matti = [2,5,5,4,5,6,3,7,6]
    D = {}
    for a in A:
        D[Matti[a-1]] = a
    D = sorted(D.items())
    #print(D)
    dp = [-inf]*(N+10)
    dp[0] = 0
    for i in range(N):
        for matti,num in D:
            dp[i+matti] = max(dp[i+matti],dp[i]+1)
    #print(dp[:N+1])
    D = sorted(D, key=lambda x: x[1], reverse=True)
    #print(D)
    used = []
    i = N
    for matti,num in D:
        while (i > 0):
            # print(i)
            # input()
            #print(i,matti,used)
            if i-matti<0:
                break
            if dp[i-matti]==dp[i]-1:
                used.append(num)
                i -= matti
            else:
                break
    #print(used)
    used.sort(reverse=True)
    ans = "".join(map(str,used))
    print(ans)
    return examD N, M = LI() N LI() LI M A = LI() A LI() LI A.sort() A.sort A sort Matti = [2,5,5,4,5,6,3,7,6] Matti [2,5,5,4,5,6,3,7,6] 2 5 5 4 5 6 3 7 6 D = {} D {} for a in A:
        D[Matti[a-1]] = a
     a A D[Matti[a-1]] = a D[Matti[a-1]] D Matti[a-1] Matti a-1 a 1 a D = sorted(D.items()) D sorted(D.items()) sorted D.items() D.items D items dp = [-inf]*(N+10) dp [-inf]*(N+10) [-inf] -inf inf N+10 N 10 dp[0] = 0 dp[0] dp 0 0 for i in range(N):
        for matti,num in D:
            dp[i+matti] = max(dp[i+matti],dp[i]+1)
    #print(dp[:N+1])
     i range(N) range N for matti,num in D:
            dp[i+matti] = max(dp[i+matti],dp[i]+1)
    #print(dp[:N+1])
     matti num D dp[i+matti] = max(dp[i+matti],dp[i]+1) dp[i+matti] dp i+matti i matti max(dp[i+matti],dp[i]+1) max dp[i+matti] dp i+matti i matti dp[i]+1 dp[i] dp i 1 D = sorted(D, key=lambda x: x[1], reverse=True) D sorted(D, key=lambda x: x[1], reverse=True) sorted D key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x reverse=True reverse True used = [] used [] i = N i N for matti,num in D:
        while (i > 0):
            # print(i)
            # input()
            #print(i,matti,used)
            if i-matti<0:
                break
            if dp[i-matti]==dp[i]-1:
                used.append(num)
                i -= matti
            else:
                break
    #print(used)
     matti num D while (i > 0):
            # print(i)
            # input()
            #print(i,matti,used)
            if i-matti<0:
                break
            if dp[i-matti]==dp[i]-1:
                used.append(num)
                i -= matti
            else:
                break
    #print(used)
     i > 0 i 0 if i-matti<0:
                break
             i-matti<0 i-matti i matti 0 break if dp[i-matti]==dp[i]-1:
                used.append(num)
                i -= matti
            else:
                break
    #print(used)
     dp[i-matti]==dp[i]-1 dp[i-matti] dp i-matti i matti dp[i]-1 dp[i] dp i 1 used.append(num) used.append used append num i -= matti i matti break used.sort(reverse=True) used.sort used sort reverse=True reverse True ans = "".join(map(str,used)) ans "".join(map(str,used)) "".join "" join map(str,used) map str used print(ans) print ans return import sys,copy,bisect,itertools,heapq,math sys copy bisect itertools heapq math from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque def I(): return int(sys.stdin.readline()) I def LI(): return list(map(int,sys.stdin.readline().split())) LI def LSI(): return list(map(str,sys.stdin.readline().split())) LSI def LS(): return sys.stdin.readline().split() LS def SI(): return sys.stdin.readline().strip() SI global mod,mod2,inf,alphabet mod = 10**9 + 7 mod 10**9 + 7 10**9 10 9 7 mod2 = 998244353 mod2 998244353 inf = 10**18 inf 10**18 10 18 chr(ord('a') + i) for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) chr(ord('a') + i) chr ord('a') + i ord('a') ord 'a' i alphabet = [chr(ord('a') + i) for i in range(26)] alphabet [chr(ord('a') + i) for i in range(26)] if __name__ == '__main__':
    examD() __name__ == '__main__' __name__ '__main__' examD() examD """
31 2
5 8
""" def examD():
    N, M = LI()
    A = LI(); A.sort()
    Matti = [2,5,5,4,5,6,3,7,6]
    D = {}
    for a in A:
        D[Matti[a-1]] = a
    D = sorted(D.items())
    #print(D)
    dp = [-inf]*(N+10)
    dp[0] = 0
    for i in range(N):
        for matti,num in D:
            dp[i+matti] = max(dp[i+matti],dp[i]+1)
    #print(dp[:N+1])
    D = sorted(D, key=lambda x: x[1], reverse=True)
    #print(D)
    used = []
    i = N
    for matti,num in D:
        while (i > 0):
            # print(i)
            # input()
            #print(i,matti,used)
            if i-matti<0:
                break
            if dp[i-matti]==dp[i]-1:
                used.append(num)
                i -= matti
            else:
                break
    #print(used)
    used.sort(reverse=True)
    ans = "".join(map(str,used))
    print(ans)
    return def examD():
    N, M = LI()
    A = LI(); A.sort()
    Matti = [2,5,5,4,5,6,3,7,6]
    D = {}
    for a in A:
        D[Matti[a-1]] = a
    D = sorted(D.items())
    #print(D)
    dp = [-inf]*(N+10)
    dp[0] = 0
    for i in range(N):
        for matti,num in D:
            dp[i+matti] = max(dp[i+matti],dp[i]+1)
    #print(dp[:N+1])
    D = sorted(D, key=lambda x: x[1], reverse=True)
    #print(D)
    used = []
    i = N
    for matti,num in D:
        while (i > 0):
            # print(i)
            # input()
            #print(i,matti,used)
            if i-matti<0:
                break
            if dp[i-matti]==dp[i]-1:
                used.append(num)
                i -= matti
            else:
                break
    #print(used)
    used.sort(reverse=True)
    ans = "".join(map(str,used))
    print(ans)
    return examD global mod,mod2,inf,alphabet def examC():
    N = I()
    A = LI()
    cur = A[0]
    for i in range(N-1):
        cur = gcd(cur,A[i+1])
    ans = cur
    print(ans)
    return def examC():
    N = I()
    A = LI()
    cur = A[0]
    for i in range(N-1):
        cur = gcd(cur,A[i+1])
    ans = cur
    print(ans)
    return examC def LSI(): return list(map(str,sys.stdin.readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) LSI def LS(): return sys.stdin.readline().split() def LS(): return sys.stdin.readline().split() LS def examA():
    A, B = LI()
    if B%A==0:
        ans = A+B
    else:
        ans = B-A
    print(ans)
    return def examA():
    A, B = LI()
    if B%A==0:
        ans = A+B
    else:
        ans = B-A
    print(ans)
    return examA def I(): return int(sys.stdin.readline()) def I(): return int(sys.stdin.readline()) I def SI(): return sys.stdin.readline().strip() def SI(): return sys.stdin.readline().strip() SI def gcd(x,y):
    if y==0:
        return x
    while(y!=0):
        x, y = y,x%y
    return x def gcd(x,y):
    if y==0:
        return x
    while(y!=0):
        x, y = y,x%y
    return x gcd inf = 10**18 10**18 inf def LI(): return list(map(int,sys.stdin.readline().split())) def LI(): return list(map(int,sys.stdin.readline().split())) LI mod2 = 998244353 998244353 mod2 mod = 10**9 + 7 10**9 + 7 mod def examB():
    N, M = LI()
    Flag = [0]*M
    for i in range(N):
        K = LI()
        for j in range(1,K[0]+1):
            Flag[K[j]-1] +=1
    ans = 0
    for i in Flag:
        if i==N:
            ans +=1
    print(ans)
    return def examB():
    N, M = LI()
    Flag = [0]*M
    for i in range(N):
        K = LI()
        for j in range(1,K[0]+1):
            Flag[K[j]-1] +=1
    ans = 0
    for i in Flag:
        if i==N:
            ans +=1
    print(ans)
    return examB alphabet = [chr(ord('a') + i) for i in range(26)] [chr(ord('a') + i) for i in range(26)] alphabet
def examA():
    A, B = LI()
    if B%A==0:
        ans = A+B
    else:
        ans = B-A
    print(ans)
    return

def examB():
    N, M = LI()
    Flag = [0]*M
    for i in range(N):
        K = LI()
        for j in range(1,K[0]+1):
            Flag[K[j]-1] +=1
    ans = 0
    for i in Flag:
        if i==N:
            ans +=1
    print(ans)
    return

def gcd(x,y):
    if y==0:
        return x
    while(y!=0):
        x, y = y,x%y
    return x
def examC():
    N = I()
    A = LI()
    cur = A[0]
    for i in range(N-1):
        cur = gcd(cur,A[i+1])
    ans = cur
    print(ans)
    return

def examD():
    N, M = LI()
    A = LI(); A.sort()
    Matti = [2,5,5,4,5,6,3,7,6]
    D = {}
    for a in A:
        D[Matti[a-1]] = a
    D = sorted(D.items())
    #print(D)
    dp = [-inf]*(N+10)
    dp[0] = 0
    for i in range(N):
        for matti,num in D:
            dp[i+matti] = max(dp[i+matti],dp[i]+1)
    #print(dp[:N+1])
    D = sorted(D, key=lambda x: x[1], reverse=True)
    #print(D)
    used = []
    i = N
    for matti,num in D:
        while (i > 0):
            # print(i)
            # input()
            #print(i,matti,used)
            if i-matti<0:
                break
            if dp[i-matti]==dp[i]-1:
                used.append(num)
                i -= matti
            else:
                break
    #print(used)
    used.sort(reverse=True)
    ans = "".join(map(str,used))
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examD()


"""
31 2
5 8
"""