N, M = map(int, input().split())
*A, = map(int, input().split())

d = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
c = [(i, d[i]) for i in A]
minpos = min(c, key=lambda x:x[1])[1]

dp = [0] * (N+1)
digit = [0] * (N+1)

for i in range(minpos, N+1):
    for n, cost in c:
        if i-cost<0 or 0<i-cost<minpos: continue
        a = dp[i]
        b = dp[i-cost] + n * (10**(digit[i-cost]))
        if a<b:
            dp[i] = b
            digit[i] = digit[i-cost] + 1

print(dp[N]) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M *A, = map(int, input().split()) *A A map(int, input().split()) map int input().split() ().split () input split d = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6} d {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 (i, d[i]) for i in A for i in A i A for i in A (i, d[i]) i d[i] d i c = [(i, d[i]) for i in A] c [(i, d[i]) for i in A] minpos = min(c, key=lambda x:x[1])[1] minpos min(c, key=lambda x:x[1])[1] (c, key=lambda x:x[1]) min c key=lambda x:x[1] key lambda x:x[1] x[1] x 1 x 1 dp = [0] * (N+1) dp [0] * (N+1) [0] 0 N+1 N 1 digit = [0] * (N+1) digit [0] * (N+1) [0] 0 N+1 N 1 for i in range(minpos, N+1):
    for n, cost in c:
        if i-cost<0 or 0<i-cost<minpos: continue
        a = dp[i]
        b = dp[i-cost] + n * (10**(digit[i-cost]))
        if a<b:
            dp[i] = b
            digit[i] = digit[i-cost] + 1 i range(minpos, N+1) range minpos N+1 N 1 for n, cost in c:
        if i-cost<0 or 0<i-cost<minpos: continue
        a = dp[i]
        b = dp[i-cost] + n * (10**(digit[i-cost]))
        if a<b:
            dp[i] = b
            digit[i] = digit[i-cost] + 1 n cost c if i-cost<0 or 0<i-cost<minpos: continue
         i-cost<0 or 0<i-cost<minpos i-cost<0 i-cost i cost 0 0<i-cost<minpos 0<i-cost 0 i-cost i cost minpos a = dp[i] a dp[i] dp i b = dp[i-cost] + n * (10**(digit[i-cost])) b dp[i-cost] + n * (10**(digit[i-cost])) dp[i-cost] dp i-cost i cost n * (10**(digit[i-cost])) n 10**(digit[i-cost]) 10 digit[i-cost] digit i-cost i cost if a<b:
            dp[i] = b
            digit[i] = digit[i-cost] + 1 a<b a b dp[i] = b dp[i] dp i b digit[i] = digit[i-cost] + 1 digit[i] digit i digit[i-cost] + 1 digit[i-cost] digit i-cost i cost 1 print(dp[N]) print dp[N] dp N minpos = min(c, key=lambda x:x[1])[1] min(c, key=lambda x:x[1])[1] minpos N, M = map(int, input().split()) map(int, input().split()) N M = map(int, input().split()) map(int, input().split()) M d = {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} d a = dp[i] dp[i] a c = [(i, d[i]) for i in A] [(i, d[i]) for i in A] c b = dp[i-cost] + n * (10**(digit[i-cost])) dp[i-cost] + n * (10**(digit[i-cost])) b dp = [0] * (N+1) [0] * (N+1) dp digit = [0] * (N+1) [0] * (N+1) digit
N, M = map(int, input().split())
*A, = map(int, input().split())

d = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
c = [(i, d[i]) for i in A]
minpos = min(c, key=lambda x:x[1])[1]

dp = [0] * (N+1)
digit = [0] * (N+1)

for i in range(minpos, N+1):
    for n, cost in c:
        if i-cost<0 or 0<i-cost<minpos: continue
        a = dp[i]
        b = dp[i-cost] + n * (10**(digit[i-cost]))
        if a<b:
            dp[i] = b
            digit[i] = digit[i-cost] + 1

print(dp[N])