num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
N, M = map(int, input().split())
A = [int(s) for s in input().split()]
A.sort(reverse = True)

dp = [0]*(N+1);
MIN = -10**9
for i in range(1, N+1):
    mx = MIN
    for a in A:
        k = i-num[a]
        if k >= 0:
            mx = max(mx, dp[k] + 1)
    dp[i] = mx

d = dp[N]
n = N
s = []
for i in range(0, d):
    for a in A:
        tmp = n-num[a]
        if tmp >= 0 and dp[tmp] == dp[n]-1:
            s.append(str(a))
            n -= num[a]
            break
print("".join(s)) num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] num [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] 0 2 5 5 4 5 6 3 7 6 N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M int(s) for s in input().split() for s in input().split() s input().split() ().split () input split for s in input().split() int(s) int s A = [int(s) for s in input().split()] A [int(s) for s in input().split()] A.sort(reverse = True) A.sort A sort reverse = True reverse True dp = [0]*(N+1) dp [0]*(N+1) [0] 0 N+1 N 1 MIN = -10**9 MIN -10**9 -10 9 for i in range(1, N+1):
    mx = MIN
    for a in A:
        k = i-num[a]
        if k >= 0:
            mx = max(mx, dp[k] + 1)
    dp[i] = mx i range(1, N+1) range 1 N+1 N 1 mx = MIN mx MIN for a in A:
        k = i-num[a]
        if k >= 0:
            mx = max(mx, dp[k] + 1)
     a A k = i-num[a] k i-num[a] i num[a] num a if k >= 0:
            mx = max(mx, dp[k] + 1)
     k >= 0 k 0 mx = max(mx, dp[k] + 1) mx max(mx, dp[k] + 1) max mx dp[k] + 1 dp[k] dp k 1 dp[i] = mx dp[i] dp i mx d = dp[N] d dp[N] dp N n = N n N s = [] s [] for i in range(0, d):
    for a in A:
        tmp = n-num[a]
        if tmp >= 0 and dp[tmp] == dp[n]-1:
            s.append(str(a))
            n -= num[a]
            break i range(0, d) range 0 d for a in A:
        tmp = n-num[a]
        if tmp >= 0 and dp[tmp] == dp[n]-1:
            s.append(str(a))
            n -= num[a]
            break a A tmp = n-num[a] tmp n-num[a] n num[a] num a if tmp >= 0 and dp[tmp] == dp[n]-1:
            s.append(str(a))
            n -= num[a]
            break tmp >= 0 and dp[tmp] == dp[n]-1 tmp >= 0 tmp 0 dp[tmp] == dp[n]-1 dp[tmp] dp tmp dp[n]-1 dp[n] dp n 1 s.append(str(a)) s.append s append str(a) str a n -= num[a] n num[a] num a break print("".join(s)) print "".join(s) "".join "" join s n = N N n MIN = -10**9 -10**9 MIN dp = [0]*(N+1) [0]*(N+1) dp num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] num tmp = n-num[a] n-num[a] tmp mx = MIN MIN mx A = [int(s) for s in input().split()] [int(s) for s in input().split()] A N, M = map(int, input().split()) map(int, input().split()) N s = [] [] s n -= num[a] num[a] n k = i-num[a] i-num[a] k mx = max(mx, dp[k] + 1) max(mx, dp[k] + 1) mx d = dp[N] dp[N] d M = map(int, input().split()) map(int, input().split()) M
num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
N, M = map(int, input().split())
A = [int(s) for s in input().split()]
A.sort(reverse = True)

dp = [0]*(N+1);
MIN = -10**9
for i in range(1, N+1):
    mx = MIN
    for a in A:
        k = i-num[a]
        if k >= 0:
            mx = max(mx, dp[k] + 1)
    dp[i] = mx

d = dp[N]
n = N
s = []
for i in range(0, d):
    for a in A:
        tmp = n-num[a]
        if tmp >= 0 and dp[tmp] == dp[n]-1:
            s.append(str(a))
            n -= num[a]
            break
print("".join(s))