n, m = map(int, input().split())
a = list(map(int, input().split()))
matches = [100, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [""]
for i in range(1, n + 1):
    dp.append(None)
    for d in a:
        m = matches[d]
        if i - m >= 0 and dp[i - m] is not None:
            r = max(dp[i - m] + str(d), str(d) + dp[i - m])
            if dp[i] is None or len(r) > len(dp[i]) or len(r) == len(dp[i]) and r > dp[i]:
                dp[i] = r
print(dp[n]) 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 matches = [100, 2, 5, 5, 4, 5, 6, 3, 7, 6] matches [100, 2, 5, 5, 4, 5, 6, 3, 7, 6] 100 2 5 5 4 5 6 3 7 6 dp = [""] dp [""] "" for i in range(1, n + 1):
    dp.append(None)
    for d in a:
        m = matches[d]
        if i - m >= 0 and dp[i - m] is not None:
            r = max(dp[i - m] + str(d), str(d) + dp[i - m])
            if dp[i] is None or len(r) > len(dp[i]) or len(r) == len(dp[i]) and r > dp[i]:
                dp[i] = r i range(1, n + 1) range 1 n + 1 n 1 dp.append(None) dp.append dp append None for d in a:
        m = matches[d]
        if i - m >= 0 and dp[i - m] is not None:
            r = max(dp[i - m] + str(d), str(d) + dp[i - m])
            if dp[i] is None or len(r) > len(dp[i]) or len(r) == len(dp[i]) and r > dp[i]:
                dp[i] = r d a m = matches[d] m matches[d] matches d if i - m >= 0 and dp[i - m] is not None:
            r = max(dp[i - m] + str(d), str(d) + dp[i - m])
            if dp[i] is None or len(r) > len(dp[i]) or len(r) == len(dp[i]) and r > dp[i]:
                dp[i] = r i - m >= 0 and dp[i - m] is not None i - m >= 0 i - m i m 0 dp[i - m] is not None dp[i - m] dp i - m i m None r = max(dp[i - m] + str(d), str(d) + dp[i - m]) r max(dp[i - m] + str(d), str(d) + dp[i - m]) max dp[i - m] + str(d) dp[i - m] dp i - m i m str(d) str d str(d) + dp[i - m] str(d) str d dp[i - m] dp i - m i m if dp[i] is None or len(r) > len(dp[i]) or len(r) == len(dp[i]) and r > dp[i]:
                dp[i] = r dp[i] is None or len(r) > len(dp[i]) or len(r) == len(dp[i]) and r > dp[i] dp[i] is None or len(r) > len(dp[i]) dp[i] is None dp[i] dp i None len(r) > len(dp[i]) len(r) len r len(dp[i]) len dp[i] dp i len(r) == len(dp[i]) and r > dp[i] len(r) == len(dp[i]) len(r) len r len(dp[i]) len dp[i] dp i r > dp[i] r dp[i] dp i dp[i] = r dp[i] dp i r print(dp[n]) print dp[n] dp n m = map(int, input().split()) map(int, input().split()) m m = matches[d] matches[d] m n, m = map(int, input().split()) map(int, input().split()) n a = list(map(int, input().split())) list(map(int, input().split())) a matches = [100, 2, 5, 5, 4, 5, 6, 3, 7, 6] [100, 2, 5, 5, 4, 5, 6, 3, 7, 6] matches r = max(dp[i - m] + str(d), str(d) + dp[i - m]) max(dp[i - m] + str(d), str(d) + dp[i - m]) r dp = [""] [""] dp
n, m = map(int, input().split())
a = list(map(int, input().split()))
matches = [100, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [""]
for i in range(1, n + 1):
    dp.append(None)
    for d in a:
        m = matches[d]
        if i - m >= 0 and dp[i - m] is not None:
            r = max(dp[i - m] + str(d), str(d) + dp[i - m])
            if dp[i] is None or len(r) > len(dp[i]) or len(r) == len(dp[i]) and r > dp[i]:
                dp[i] = r
print(dp[n])
