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

match = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
}

dp = ["-" for _ in range(11000)]
dp[0] = ""


def _max(a, b):
    if len(a) > len(b):
        return a
    if len(a) < len(b):
        return b
    return max(a, b)


for i in range(N+1):
    if dp[i] == "-":
        continue
    for a in A:
        dp[i+match[a]] = _max(dp[i+match[a]], dp[i]+str(a))

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 match = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
} match {
    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 "-" for _ in range(11000) for _ in range(11000) _ range(11000) range 11000 for _ in range(11000) "-" dp = ["-" for _ in range(11000)] dp ["-" for _ in range(11000)] dp[0] = "" dp[0] dp 0 "" def _max(a, b):
    if len(a) > len(b):
        return a
    if len(a) < len(b):
        return b
    return max(a, b) _max if len(a) > len(b):
        return a
     len(a) > len(b) len(a) len a len(b) len b return a a if len(a) < len(b):
        return b
     len(a) < len(b) len(a) len a len(b) len b return b b return max(a, b) max(a, b) max a b a a b b for i in range(N+1):
    if dp[i] == "-":
        continue
    for a in A:
        dp[i+match[a]] = _max(dp[i+match[a]], dp[i]+str(a)) i range(N+1) range N+1 N 1 if dp[i] == "-":
        continue
     dp[i] == "-" dp[i] dp i "-" continue for a in A:
        dp[i+match[a]] = _max(dp[i+match[a]], dp[i]+str(a)) a A dp[i+match[a]] = _max(dp[i+match[a]], dp[i]+str(a)) dp[i+match[a]] dp i+match[a] i match[a] match a _max(dp[i+match[a]], dp[i]+str(a)) _max dp[i+match[a]] dp i+match[a] i match[a] match a dp[i]+str(a) dp[i] dp i str(a) str a print(dp[N]) print dp[N] dp N M = map(int, input().split()) map(int, input().split()) M dp = ["-" for _ in range(11000)] ["-" for _ in range(11000)] dp N, M = map(int, input().split()) map(int, input().split()) N def _max(a, b):
    if len(a) > len(b):
        return a
    if len(a) < len(b):
        return b
    return max(a, b) def _max(a, b):
    if len(a) > len(b):
        return a
    if len(a) < len(b):
        return b
    return max(a, b) _max A = list(map(int, input().split())) list(map(int, input().split())) A match = {
    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,
} match
N, M = map(int, input().split())
A = list(map(int, input().split()))

match = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
}

dp = ["-" for _ in range(11000)]
dp[0] = ""


def _max(a, b):
    if len(a) > len(b):
        return a
    if len(a) < len(b):
        return b
    return max(a, b)


for i in range(N+1):
    if dp[i] == "-":
        continue
    for a in A:
        dp[i+match[a]] = _max(dp[i+match[a]], dp[i]+str(a))

print(dp[N])

