MINUS_INF = "-"
MATCHES = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6]

def char_max(a, b):
    if a == MINUS_INF:
        return b
    la, lb = len(a), len(b)
    if la < lb:
        return b
    elif la == lb and a < b:
        return b
    return a


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

dp = [MINUS_INF]*(10**4+10)
dp[0] = ""
for i in range(N+1):
    if dp[i] == MINUS_INF:
        continue
    for a in A:
        # 配るdp?
        dp[i+MATCHES[int(a)]] = char_max(
            dp[i+MATCHES[int(a)]],
            dp[i] + a
        )

print(dp[N]) MINUS_INF = "-" MINUS_INF "-" MATCHES = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6] MATCHES [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6] -1 2 5 5 4 5 6 3 7 6 def char_max(a, b):
    if a == MINUS_INF:
        return b
    la, lb = len(a), len(b)
    if la < lb:
        return b
    elif la == lb and a < b:
        return b
    return a char_max if a == MINUS_INF:
        return b
     a == MINUS_INF a MINUS_INF return b b la, lb = len(a), len(b) la len(a) len a lb len(b) len b if la < lb:
        return b
    elif la == lb and a < b:
        return b
     la < lb la lb return b b elif la == lb and a < b:
        return b
     la == lb and a < b la == lb la lb a < b a b return b b return a a a a b b N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M A = input().split() A input().split() ().split () input split dp = [MINUS_INF]*(10**4+10) dp [MINUS_INF]*(10**4+10) [MINUS_INF] MINUS_INF 10**4+10 10**4 10 4 10 dp[0] = "" dp[0] dp 0 "" for i in range(N+1):
    if dp[i] == MINUS_INF:
        continue
    for a in A:
        # 配るdp?
        dp[i+MATCHES[int(a)]] = char_max(
            dp[i+MATCHES[int(a)]],
            dp[i] + a
        ) i range(N+1) range N+1 N 1 if dp[i] == MINUS_INF:
        continue
     dp[i] == MINUS_INF dp[i] dp i MINUS_INF continue for a in A:
        # 配るdp?
        dp[i+MATCHES[int(a)]] = char_max(
            dp[i+MATCHES[int(a)]],
            dp[i] + a
        ) a A dp[i+MATCHES[int(a)]] = char_max(
            dp[i+MATCHES[int(a)]],
            dp[i] + a
        ) dp[i+MATCHES[int(a)]] dp i+MATCHES[int(a)] i MATCHES[int(a)] MATCHES int(a) int a char_max(
            dp[i+MATCHES[int(a)]],
            dp[i] + a
        ) char_max dp[i+MATCHES[int(a)]] dp i+MATCHES[int(a)] i MATCHES[int(a)] MATCHES int(a) int a dp[i] + a dp[i] dp i a print(dp[N]) print dp[N] dp N def char_max(a, b):
    if a == MINUS_INF:
        return b
    la, lb = len(a), len(b)
    if la < lb:
        return b
    elif la == lb and a < b:
        return b
    return a def char_max(a, b):
    if a == MINUS_INF:
        return b
    la, lb = len(a), len(b)
    if la < lb:
        return b
    elif la == lb and a < b:
        return b
    return a char_max N, M = map(int, input().split()) map(int, input().split()) N M = map(int, input().split()) map(int, input().split()) M A = input().split() input().split() A dp = [MINUS_INF]*(10**4+10) [MINUS_INF]*(10**4+10) dp MINUS_INF = "-" "-" MINUS_INF MATCHES = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6] [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6] MATCHES
MINUS_INF = "-"
MATCHES = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6]

def char_max(a, b):
    if a == MINUS_INF:
        return b
    la, lb = len(a), len(b)
    if la < lb:
        return b
    elif la == lb and a < b:
        return b
    return a


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

dp = [MINUS_INF]*(10**4+10)
dp[0] = ""
for i in range(N+1):
    if dp[i] == MINUS_INF:
        continue
    for a in A:
        # 配るdp?
        dp[i+MATCHES[int(a)]] = char_max(
            dp[i+MATCHES[int(a)]],
            dp[i] + a
        )

print(dp[N])