#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,M = MI()
    A=sorted(LI(), reverse=True)
    num_cost = {
        1:2,
        2:5,
        3:5,
        4:4,
        5:5,
        6:6,
        7:3,
        8:7,
        9:6
    }


    dp = [-inf]*(N+1) #dp[i]:ちょうどi本使ったときの最大桁数
    dp[0] = 0

    for i in range(1,N+1):
        for a in A:
            if i-num_cost[a]>=0:
                dp[i] = max(dp[i], dp[i-num_cost[a]] + 1)

    ans = []
    while N:
        for a in A:
            cost = num_cost[a]
            if N-cost>=0 and dp[N-cost]==dp[N]-1: #aを使って最大桁数で作れる
                ans.append(a)
                N-=cost
                break
    print(*ans,sep="")



if __name__ == '__main__':
    main() import sys sys sys.setrecursionlimit(10**6) sys.setrecursionlimit sys setrecursionlimit 10**6 10 6 input=sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline from math import floor,ceil,sqrt,factorial,hypot,log from heapq import heappop, heappush, heappushpop from collections import Counter,defaultdict,deque from itertools import accumulate,permutations,combinations,product,combinations_with_replacement from bisect import bisect_left,bisect_right from copy import deepcopy inf=float('inf') inf float('inf') float 'inf' mod = 10**9+7 mod 10**9+7 10**9 10 9 7 def pprint(*A): 
    for a in A:     print(*a,sep='\n') pprint for a in A:     print(*a,sep=' a A *A def INT_(n): return int(n)-1 INT_ n n def MI(): return map(int,input().split()) MI def MF(): return map(float, input().split()) MF def MI_(): return map(INT_,input().split()) MI_ def LI(): return list(MI()) LI int(x) - 1 for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) - 1 int(x) int x 1 def LI_(): return [int(x) - 1 for x in input().split()] LI_ def LF(): return list(MF()) LF I() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) I() I def LIN(n:int): return [I() for _ in range(n)] LIN n:int n LI() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) LI() LI def LLIN(n: int): return [LI() for _ in range(n)] LLIN n: int n LI_() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) LI_() LI_ def LLIN_(n: int): return [LI_() for _ in range(n)] LLIN_ n: int n list(map(int, l.split() )) for l in input() for l in input() l input() input for l in input() list(map(int, l.split() )) list map(int, l.split() ) map int l.split() l.split l split def LLI(): return [list(map(int, l.split() )) for l in input()] LLI def I(): return int(input()) I def F(): return float(input()) F def ST(): return input().replace('\n', '') ST def main():
    N,M = MI()
    A=sorted(LI(), reverse=True)
    num_cost = {
        1:2,
        2:5,
        3:5,
        4:4,
        5:5,
        6:6,
        7:3,
        8:7,
        9:6
    }


    dp = [-inf]*(N+1) #dp[i]:ちょうどi本使ったときの最大桁数
    dp[0] = 0

    for i in range(1,N+1):
        for a in A:
            if i-num_cost[a]>=0:
                dp[i] = max(dp[i], dp[i-num_cost[a]] + 1)

    ans = []
    while N:
        for a in A:
            cost = num_cost[a]
            if N-cost>=0 and dp[N-cost]==dp[N]-1: #aを使って最大桁数で作れる
                ans.append(a)
                N-=cost
                break
    print(*ans,sep="") main N,M = MI() N MI() MI M A=sorted(LI(), reverse=True) A sorted(LI(), reverse=True) sorted LI() LI reverse=True reverse True num_cost = {
        1:2,
        2:5,
        3:5,
        4:4,
        5:5,
        6:6,
        7:3,
        8:7,
        9:6
    } num_cost {
        1:2,
        2:5,
        3:5,
        4:4,
        5:5,
        6:6,
        7:3,
        8:7,
        9:6
    } 1 1 2 2 2 5 3 3 5 4 4 4 5 5 5 6 6 6 7 7 3 8 8 7 9 9 6 dp = [-inf]*(N+1) dp [-inf]*(N+1) [-inf] -inf inf N+1 N 1 dp[0] = 0 dp[0] dp 0 0 for i in range(1,N+1):
        for a in A:
            if i-num_cost[a]>=0:
                dp[i] = max(dp[i], dp[i-num_cost[a]] + 1)

     i range(1,N+1) range 1 N+1 N 1 for a in A:
            if i-num_cost[a]>=0:
                dp[i] = max(dp[i], dp[i-num_cost[a]] + 1)

     a A if i-num_cost[a]>=0:
                dp[i] = max(dp[i], dp[i-num_cost[a]] + 1)

     i-num_cost[a]>=0 i-num_cost[a] i num_cost[a] num_cost a 0 dp[i] = max(dp[i], dp[i-num_cost[a]] + 1) dp[i] dp i max(dp[i], dp[i-num_cost[a]] + 1) max dp[i] dp i dp[i-num_cost[a]] + 1 dp[i-num_cost[a]] dp i-num_cost[a] i num_cost[a] num_cost a 1 ans = [] ans [] while N:
        for a in A:
            cost = num_cost[a]
            if N-cost>=0 and dp[N-cost]==dp[N]-1: #aを使って最大桁数で作れる
                ans.append(a)
                N-=cost
                break
     N for a in A:
            cost = num_cost[a]
            if N-cost>=0 and dp[N-cost]==dp[N]-1: #aを使って最大桁数で作れる
                ans.append(a)
                N-=cost
                break
     a A cost = num_cost[a] cost num_cost[a] num_cost a if N-cost>=0 and dp[N-cost]==dp[N]-1: #aを使って最大桁数で作れる
                ans.append(a)
                N-=cost
                break
     N-cost>=0 and dp[N-cost]==dp[N]-1 N-cost>=0 N-cost N cost 0 dp[N-cost]==dp[N]-1 dp[N-cost] dp N-cost N cost dp[N]-1 dp[N] dp N 1 ans.append(a) ans.append ans append a N-=cost N cost break print(*ans,sep="") print *ans ans sep="" sep "" if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main input=sys.stdin.readline sys.stdin.readline input def LLIN_(n: int): return [LI_() for _ in range(n)] def LLIN_(n: int): return [LI_() for _ in range(n)] LLIN_ def MF(): return map(float, input().split()) def MF(): return map(float, input().split()) MF def LIN(n:int): return [I() for _ in range(n)] def LIN(n:int): return [I() for _ in range(n)] LIN def LLIN(n: int): return [LI() for _ in range(n)] def LLIN(n: int): return [LI() for _ in range(n)] LLIN def pprint(*A): 
    for a in A:     print(*a,sep='\n') def pprint(*A): 
    for a in A:     print(*a,sep='\n') pprint def INT_(n): return int(n)-1 def INT_(n): return int(n)-1 INT_ def LI(): return list(MI()) def LI(): return list(MI()) LI def ST(): return input().replace('\n', '') def ST(): return input().replace('\n', '') ST def LI_(): return [int(x) - 1 for x in input().split()] def LI_(): return [int(x) - 1 for x in input().split()] LI_ mod = 10**9+7 10**9+7 mod def I(): return int(input()) def I(): return int(input()) I def main():
    N,M = MI()
    A=sorted(LI(), reverse=True)
    num_cost = {
        1:2,
        2:5,
        3:5,
        4:4,
        5:5,
        6:6,
        7:3,
        8:7,
        9:6
    }


    dp = [-inf]*(N+1) #dp[i]:ちょうどi本使ったときの最大桁数
    dp[0] = 0

    for i in range(1,N+1):
        for a in A:
            if i-num_cost[a]>=0:
                dp[i] = max(dp[i], dp[i-num_cost[a]] + 1)

    ans = []
    while N:
        for a in A:
            cost = num_cost[a]
            if N-cost>=0 and dp[N-cost]==dp[N]-1: #aを使って最大桁数で作れる
                ans.append(a)
                N-=cost
                break
    print(*ans,sep="") def main():
    N,M = MI()
    A=sorted(LI(), reverse=True)
    num_cost = {
        1:2,
        2:5,
        3:5,
        4:4,
        5:5,
        6:6,
        7:3,
        8:7,
        9:6
    }


    dp = [-inf]*(N+1) #dp[i]:ちょうどi本使ったときの最大桁数
    dp[0] = 0

    for i in range(1,N+1):
        for a in A:
            if i-num_cost[a]>=0:
                dp[i] = max(dp[i], dp[i-num_cost[a]] + 1)

    ans = []
    while N:
        for a in A:
            cost = num_cost[a]
            if N-cost>=0 and dp[N-cost]==dp[N]-1: #aを使って最大桁数で作れる
                ans.append(a)
                N-=cost
                break
    print(*ans,sep="") main def MI(): return map(int,input().split()) def MI(): return map(int,input().split()) MI def MI_(): return map(INT_,input().split()) def MI_(): return map(INT_,input().split()) MI_ def LF(): return list(MF()) def LF(): return list(MF()) LF def F(): return float(input()) def F(): return float(input()) F inf=float('inf') float('inf') inf def LLI(): return [list(map(int, l.split() )) for l in input()] def LLI(): return [list(map(int, l.split() )) for l in input()] LLI
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,M = MI()
    A=sorted(LI(), reverse=True)
    num_cost = {
        1:2,
        2:5,
        3:5,
        4:4,
        5:5,
        6:6,
        7:3,
        8:7,
        9:6
    }


    dp = [-inf]*(N+1) #dp[i]:ちょうどi本使ったときの最大桁数
    dp[0] = 0

    for i in range(1,N+1):
        for a in A:
            if i-num_cost[a]>=0:
                dp[i] = max(dp[i], dp[i-num_cost[a]] + 1)

    ans = []
    while N:
        for a in A:
            cost = num_cost[a]
            if N-cost>=0 and dp[N-cost]==dp[N]-1: #aを使って最大桁数で作れる
                ans.append(a)
                N-=cost
                break
    print(*ans,sep="")



if __name__ == '__main__':
    main()