n, m = map(int, input().split())
a = list(map(int, input().split()))
matchlist = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
numberlist = []
for i in range(m):
    numberlist.append(matchlist[a[i]])
numberlist = set(numberlist)
#dp[i]:i本でのmax桁
dp = [-10000000]*(n+1)
dp[0] = 0
for i in range(n):
    for j in numberlist:
        if i+j <= n:
            dp[i+j] = max(dp[i+j], dp[i]+1)


ans = []
d = dp[n]
a.sort(reverse = True)
for i in range(d):
    for j in a:
        if n - matchlist[j] >= 0:
            if dp[n] == dp[n-matchlist[j]] + 1:
                n -= matchlist[j]
                ans.append(j)
                break
print("".join(map(str,ans))) 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 matchlist = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] matchlist [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] 0 2 5 5 4 5 6 3 7 6 numberlist = [] numberlist [] for i in range(m):
    numberlist.append(matchlist[a[i]]) i range(m) range m numberlist.append(matchlist[a[i]]) numberlist.append numberlist append matchlist[a[i]] matchlist a[i] a i numberlist = set(numberlist) numberlist set(numberlist) set numberlist dp = [-10000000]*(n+1) dp [-10000000]*(n+1) [-10000000] -10000000 n+1 n 1 dp[0] = 0 dp[0] dp 0 0 for i in range(n):
    for j in numberlist:
        if i+j <= n:
            dp[i+j] = max(dp[i+j], dp[i]+1) i range(n) range n for j in numberlist:
        if i+j <= n:
            dp[i+j] = max(dp[i+j], dp[i]+1) j numberlist if i+j <= n:
            dp[i+j] = max(dp[i+j], dp[i]+1) i+j <= n i+j i j n dp[i+j] = max(dp[i+j], dp[i]+1) dp[i+j] dp i+j i j max(dp[i+j], dp[i]+1) max dp[i+j] dp i+j i j dp[i]+1 dp[i] dp i 1 ans = [] ans [] d = dp[n] d dp[n] dp n a.sort(reverse = True) a.sort a sort reverse = True reverse True for i in range(d):
    for j in a:
        if n - matchlist[j] >= 0:
            if dp[n] == dp[n-matchlist[j]] + 1:
                n -= matchlist[j]
                ans.append(j)
                break i range(d) range d for j in a:
        if n - matchlist[j] >= 0:
            if dp[n] == dp[n-matchlist[j]] + 1:
                n -= matchlist[j]
                ans.append(j)
                break j a if n - matchlist[j] >= 0:
            if dp[n] == dp[n-matchlist[j]] + 1:
                n -= matchlist[j]
                ans.append(j)
                break n - matchlist[j] >= 0 n - matchlist[j] n matchlist[j] matchlist j 0 if dp[n] == dp[n-matchlist[j]] + 1:
                n -= matchlist[j]
                ans.append(j)
                break dp[n] == dp[n-matchlist[j]] + 1 dp[n] dp n dp[n-matchlist[j]] + 1 dp[n-matchlist[j]] dp n-matchlist[j] n matchlist[j] matchlist j 1 n -= matchlist[j] n matchlist[j] matchlist j ans.append(j) ans.append ans append j break print("".join(map(str,ans))) print "".join(map(str,ans)) "".join "" join map(str,ans) map str ans m = map(int, input().split()) map(int, input().split()) m dp = [-10000000]*(n+1) [-10000000]*(n+1) dp a = list(map(int, input().split())) list(map(int, input().split())) a d = dp[n] dp[n] d n -= matchlist[j] matchlist[j] n numberlist = set(numberlist) set(numberlist) numberlist ans = [] [] ans n, m = map(int, input().split()) map(int, input().split()) n matchlist = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] matchlist numberlist = [] [] numberlist
n, m = map(int, input().split())
a = list(map(int, input().split()))
matchlist = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
numberlist = []
for i in range(m):
    numberlist.append(matchlist[a[i]])
numberlist = set(numberlist)
#dp[i]:i本でのmax桁
dp = [-10000000]*(n+1)
dp[0] = 0
for i in range(n):
    for j in numberlist:
        if i+j <= n:
            dp[i+j] = max(dp[i+j], dp[i]+1)


ans = []
d = dp[n]
a.sort(reverse = True)
for i in range(d):
    for j in a:
        if n - matchlist[j] >= 0:
            if dp[n] == dp[n-matchlist[j]] + 1:
                n -= matchlist[j]
                ans.append(j)
                break
print("".join(map(str,ans)))
