import copy


n,m = [int(_) for _ in input().split()]
a = [int(_) for _ in input().split()]
dict = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}
dict2 = {1:1, 2:10**4, 3:10**8, 4:10**12, 5:10**16, 6:10**20, 7:10**24, 8:10**28, 9:10**32}
bonus = 10**36
l = []
for i in a:
    l.append((i,dict[i],dict2[i]))

dp = [[['n',0,[]] for j in range(n+1)] for i in range(m+1)]
for i in range(m+1):
    dp[i][0][0] = "t"
for i in range(1,m+1):
    num = l[i-1][0]
    c = l[i-1][1]
    v = l[i-1][2]
    for j in range(1, n+1):
        if (j-c < 0 or dp[i][j-c][0] == 'n') and dp[i-1][j][0] == 'n':
            continue
        elif (j-c < 0 or dp[i][j-c][0] == 'n'):
            dp[i][j] = copy.copy(dp[i-1][j])
        elif dp[i-1][j][0] == 'n':
            dp[i][j][0] = 't'
            dp[i][j][1] = dp[i][j-c][1] + v + bonus
            dp[i][j][2] = copy.copy(dp[i][j-c][2])
            dp[i][j][2].append(num)
        else:
            dp[i][j][0] = 't'
            if dp[i-1][j][1] >= dp[i][j-c][1]+v+bonus:
                dp[i][j] = copy.copy(dp[i-1][j])
            else:
                dp[i][j][1] = dp[i][j-c][1]+v+bonus
                dp[i][j][2] = copy.copy(dp[i][j-c][2])
                dp[i][j][2].append(num)
L = dp[m][n][2]
L = sorted(L, reverse=True)
ans = ''
for i in range(len(L)):
    ans += str(L[i])
print(int(ans)) import copy copy int(_) for _ in input().split() for _ in input().split() _ input().split() ().split () input split for _ in input().split() int(_) int _ n,m = [int(_) for _ in input().split()] n [int(_) for _ in input().split()] m int(_) for _ in input().split() for _ in input().split() _ input().split() ().split () input split for _ in input().split() int(_) int _ a = [int(_) for _ in input().split()] a [int(_) for _ in input().split()] dict = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6} dict {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 dict2 = {1:1, 2:10**4, 3:10**8, 4:10**12, 5:10**16, 6:10**20, 7:10**24, 8:10**28, 9:10**32} dict2 {1:1, 2:10**4, 3:10**8, 4:10**12, 5:10**16, 6:10**20, 7:10**24, 8:10**28, 9:10**32} 1 1 1 2 2 10**4 10 4 3 3 10**8 10 8 4 4 10**12 10 12 5 5 10**16 10 16 6 6 10**20 10 20 7 7 10**24 10 24 8 8 10**28 10 28 9 9 10**32 10 32 bonus = 10**36 bonus 10**36 10 36 l = [] l [] for i in a:
    l.append((i,dict[i],dict2[i])) i a l.append((i,dict[i],dict2[i])) l.append l append (i,dict[i],dict2[i]) i dict[i] dict i dict2[i] dict2 i [['n',0,[]] for j in range(n+1)] for i in range(m+1) for i in range(m+1) i range(m+1) range m+1 m 1 for i in range(m+1) [['n',0,[]] for j in range(n+1)] dp = [[['n',0,[]] for j in range(n+1)] for i in range(m+1)] dp [[['n',0,[]] for j in range(n+1)] for i in range(m+1)] for i in range(m+1):
    dp[i][0][0] = "t" i range(m+1) range m+1 m 1 dp[i][0][0] = "t" dp[i][0][0] [0] [i] dp i 0 0 "t" for i in range(1,m+1):
    num = l[i-1][0]
    c = l[i-1][1]
    v = l[i-1][2]
    for j in range(1, n+1):
        if (j-c < 0 or dp[i][j-c][0] == 'n') and dp[i-1][j][0] == 'n':
            continue
        elif (j-c < 0 or dp[i][j-c][0] == 'n'):
            dp[i][j] = copy.copy(dp[i-1][j])
        elif dp[i-1][j][0] == 'n':
            dp[i][j][0] = 't'
            dp[i][j][1] = dp[i][j-c][1] + v + bonus
            dp[i][j][2] = copy.copy(dp[i][j-c][2])
            dp[i][j][2].append(num)
        else:
            dp[i][j][0] = 't'
            if dp[i-1][j][1] >= dp[i][j-c][1]+v+bonus:
                dp[i][j] = copy.copy(dp[i-1][j])
            else:
                dp[i][j][1] = dp[i][j-c][1]+v+bonus
                dp[i][j][2] = copy.copy(dp[i][j-c][2])
                dp[i][j][2].append(num) i range(1,m+1) range 1 m+1 m 1 num = l[i-1][0] num l[i-1][0] [i-1] l i-1 i 1 0 c = l[i-1][1] c l[i-1][1] [i-1] l i-1 i 1 1 v = l[i-1][2] v l[i-1][2] [i-1] l i-1 i 1 2 for j in range(1, n+1):
        if (j-c < 0 or dp[i][j-c][0] == 'n') and dp[i-1][j][0] == 'n':
            continue
        elif (j-c < 0 or dp[i][j-c][0] == 'n'):
            dp[i][j] = copy.copy(dp[i-1][j])
        elif dp[i-1][j][0] == 'n':
            dp[i][j][0] = 't'
            dp[i][j][1] = dp[i][j-c][1] + v + bonus
            dp[i][j][2] = copy.copy(dp[i][j-c][2])
            dp[i][j][2].append(num)
        else:
            dp[i][j][0] = 't'
            if dp[i-1][j][1] >= dp[i][j-c][1]+v+bonus:
                dp[i][j] = copy.copy(dp[i-1][j])
            else:
                dp[i][j][1] = dp[i][j-c][1]+v+bonus
                dp[i][j][2] = copy.copy(dp[i][j-c][2])
                dp[i][j][2].append(num) j range(1, n+1) range 1 n+1 n 1 if (j-c < 0 or dp[i][j-c][0] == 'n') and dp[i-1][j][0] == 'n':
            continue
        elif (j-c < 0 or dp[i][j-c][0] == 'n'):
            dp[i][j] = copy.copy(dp[i-1][j])
        elif dp[i-1][j][0] == 'n':
            dp[i][j][0] = 't'
            dp[i][j][1] = dp[i][j-c][1] + v + bonus
            dp[i][j][2] = copy.copy(dp[i][j-c][2])
            dp[i][j][2].append(num)
        else:
            dp[i][j][0] = 't'
            if dp[i-1][j][1] >= dp[i][j-c][1]+v+bonus:
                dp[i][j] = copy.copy(dp[i-1][j])
            else:
                dp[i][j][1] = dp[i][j-c][1]+v+bonus
                dp[i][j][2] = copy.copy(dp[i][j-c][2])
                dp[i][j][2].append(num) (j-c < 0 or dp[i][j-c][0] == 'n') and dp[i-1][j][0] == 'n' j-c < 0 or dp[i][j-c][0] == 'n' j-c < 0 j-c j c 0 dp[i][j-c][0] == 'n' dp[i][j-c][0] [j-c] [i] dp i j-c j c 0 'n' dp[i-1][j][0] == 'n' dp[i-1][j][0] [j] [i-1] dp i-1 i 1 j 0 'n' continue elif (j-c < 0 or dp[i][j-c][0] == 'n'):
            dp[i][j] = copy.copy(dp[i-1][j])
         j-c < 0 or dp[i][j-c][0] == 'n' j-c < 0 j-c j c 0 dp[i][j-c][0] == 'n' dp[i][j-c][0] [j-c] [i] dp i j-c j c 0 'n' dp[i][j] = copy.copy(dp[i-1][j]) dp[i][j] [i] dp i j copy.copy(dp[i-1][j]) copy.copy copy copy dp[i-1][j] [i-1] dp i-1 i 1 j elif dp[i-1][j][0] == 'n':
            dp[i][j][0] = 't'
            dp[i][j][1] = dp[i][j-c][1] + v + bonus
            dp[i][j][2] = copy.copy(dp[i][j-c][2])
            dp[i][j][2].append(num)
         dp[i-1][j][0] == 'n' dp[i-1][j][0] [j] [i-1] dp i-1 i 1 j 0 'n' dp[i][j][0] = 't' dp[i][j][0] [j] [i] dp i j 0 't' dp[i][j][1] = dp[i][j-c][1] + v + bonus dp[i][j][1] [j] [i] dp i j 1 dp[i][j-c][1] + v + bonus dp[i][j-c][1] + v dp[i][j-c][1] [j-c] [i] dp i j-c j c 1 v bonus dp[i][j][2] = copy.copy(dp[i][j-c][2]) dp[i][j][2] [j] [i] dp i j 2 copy.copy(dp[i][j-c][2]) copy.copy copy copy dp[i][j-c][2] [j-c] [i] dp i j-c j c 2 dp[i][j][2].append(num) [2].append [2] [j] [i] dp i j 2 append num dp[i][j][0] = 't' dp[i][j][0] [j] [i] dp i j 0 't' if dp[i-1][j][1] >= dp[i][j-c][1]+v+bonus:
                dp[i][j] = copy.copy(dp[i-1][j])
            else:
                dp[i][j][1] = dp[i][j-c][1]+v+bonus
                dp[i][j][2] = copy.copy(dp[i][j-c][2])
                dp[i][j][2].append(num) dp[i-1][j][1] >= dp[i][j-c][1]+v+bonus dp[i-1][j][1] [j] [i-1] dp i-1 i 1 j 1 dp[i][j-c][1]+v+bonus dp[i][j-c][1]+v dp[i][j-c][1] [j-c] [i] dp i j-c j c 1 v bonus dp[i][j] = copy.copy(dp[i-1][j]) dp[i][j] [i] dp i j copy.copy(dp[i-1][j]) copy.copy copy copy dp[i-1][j] [i-1] dp i-1 i 1 j dp[i][j][1] = dp[i][j-c][1]+v+bonus dp[i][j][1] [j] [i] dp i j 1 dp[i][j-c][1]+v+bonus dp[i][j-c][1]+v dp[i][j-c][1] [j-c] [i] dp i j-c j c 1 v bonus dp[i][j][2] = copy.copy(dp[i][j-c][2]) dp[i][j][2] [j] [i] dp i j 2 copy.copy(dp[i][j-c][2]) copy.copy copy copy dp[i][j-c][2] [j-c] [i] dp i j-c j c 2 dp[i][j][2].append(num) [2].append [2] [j] [i] dp i j 2 append num L = dp[m][n][2] L dp[m][n][2] [n] [m] dp m n 2 L = sorted(L, reverse=True) L sorted(L, reverse=True) sorted L reverse=True reverse True ans = '' ans '' for i in range(len(L)):
    ans += str(L[i]) i range(len(L)) range len(L) len L ans += str(L[i]) ans str(L[i]) str L[i] L i print(int(ans)) print int(ans) int ans ans += str(L[i]) str(L[i]) ans dict = {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} dict L = sorted(L, reverse=True) sorted(L, reverse=True) L bonus = 10**36 10**36 bonus l = [] [] l num = l[i-1][0] l[i-1][0] num v = l[i-1][2] l[i-1][2] v ans = '' '' ans n,m = [int(_) for _ in input().split()] [int(_) for _ in input().split()] n m = [int(_) for _ in input().split()] [int(_) for _ in input().split()] m c = l[i-1][1] l[i-1][1] c a = [int(_) for _ in input().split()] [int(_) for _ in input().split()] a dp = [[['n',0,[]] for j in range(n+1)] for i in range(m+1)] [[['n',0,[]] for j in range(n+1)] for i in range(m+1)] dp dict2 = {1:1, 2:10**4, 3:10**8, 4:10**12, 5:10**16, 6:10**20, 7:10**24, 8:10**28, 9:10**32} {1:1, 2:10**4, 3:10**8, 4:10**12, 5:10**16, 6:10**20, 7:10**24, 8:10**28, 9:10**32} dict2 L = dp[m][n][2] dp[m][n][2] L
import copy


n,m = [int(_) for _ in input().split()]
a = [int(_) for _ in input().split()]
dict = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}
dict2 = {1:1, 2:10**4, 3:10**8, 4:10**12, 5:10**16, 6:10**20, 7:10**24, 8:10**28, 9:10**32}
bonus = 10**36
l = []
for i in a:
    l.append((i,dict[i],dict2[i]))

dp = [[['n',0,[]] for j in range(n+1)] for i in range(m+1)]
for i in range(m+1):
    dp[i][0][0] = "t"
for i in range(1,m+1):
    num = l[i-1][0]
    c = l[i-1][1]
    v = l[i-1][2]
    for j in range(1, n+1):
        if (j-c < 0 or dp[i][j-c][0] == 'n') and dp[i-1][j][0] == 'n':
            continue
        elif (j-c < 0 or dp[i][j-c][0] == 'n'):
            dp[i][j] = copy.copy(dp[i-1][j])
        elif dp[i-1][j][0] == 'n':
            dp[i][j][0] = 't'
            dp[i][j][1] = dp[i][j-c][1] + v + bonus
            dp[i][j][2] = copy.copy(dp[i][j-c][2])
            dp[i][j][2].append(num)
        else:
            dp[i][j][0] = 't'
            if dp[i-1][j][1] >= dp[i][j-c][1]+v+bonus:
                dp[i][j] = copy.copy(dp[i-1][j])
            else:
                dp[i][j][1] = dp[i][j-c][1]+v+bonus
                dp[i][j][2] = copy.copy(dp[i][j-c][2])
                dp[i][j][2].append(num)
L = dp[m][n][2]
L = sorted(L, reverse=True)
ans = ''
for i in range(len(L)):
    ans += str(L[i])
print(int(ans))