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


COST = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
}
A = sorted(A, reverse=True)

best = [None for _ in range(N + 1)]
best[0] = tuple([0] * len(A))
for n in range(N + 1):
    for ai, a in enumerate(A):
        before = n - COST[a]
        if before < 0 or best[before] is None:
            continue
        val = tuple(x + (1 if i == ai else 0) for i, x in enumerate(best[before]))
        if (
            best[n] is None
            or sum(best[n]) < sum(val)
            or (sum(best[n]) == sum(val) and best[n] < val)
        ):
            best[n] = val
print(''.join(sorted(''.join(str(d) * n for d, n in zip(A, best[N])), reverse=True))) 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 COST = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
} COST {
    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 A = sorted(A, reverse=True) A sorted(A, reverse=True) sorted A reverse=True reverse True None for _ in range(N + 1) for _ in range(N + 1) _ range(N + 1) range N + 1 N 1 for _ in range(N + 1) None best = [None for _ in range(N + 1)] best [None for _ in range(N + 1)] best[0] = tuple([0] * len(A)) best[0] best 0 tuple([0] * len(A)) tuple [0] * len(A) [0] 0 len(A) len A for n in range(N + 1):
    for ai, a in enumerate(A):
        before = n - COST[a]
        if before < 0 or best[before] is None:
            continue
        val = tuple(x + (1 if i == ai else 0) for i, x in enumerate(best[before]))
        if (
            best[n] is None
            or sum(best[n]) < sum(val)
            or (sum(best[n]) == sum(val) and best[n] < val)
        ):
            best[n] = val n range(N + 1) range N + 1 N 1 for ai, a in enumerate(A):
        before = n - COST[a]
        if before < 0 or best[before] is None:
            continue
        val = tuple(x + (1 if i == ai else 0) for i, x in enumerate(best[before]))
        if (
            best[n] is None
            or sum(best[n]) < sum(val)
            or (sum(best[n]) == sum(val) and best[n] < val)
        ):
            best[n] = val ai a enumerate(A) enumerate A before = n - COST[a] before n - COST[a] n COST[a] COST a if before < 0 or best[before] is None:
            continue
         before < 0 or best[before] is None before < 0 before 0 best[before] is None best[before] best before None continue val = tuple(x + (1 if i == ai else 0) for i, x in enumerate(best[before])) val tuple(x + (1 if i == ai else 0) for i, x in enumerate(best[before])) tuple x + (1 if i == ai else 0) x 1 if i == ai else 0 i == ai i ai 1 0 if (
            best[n] is None
            or sum(best[n]) < sum(val)
            or (sum(best[n]) == sum(val) and best[n] < val)
        ):
            best[n] = val best[n] is None
            or sum(best[n]) < sum(val)
            or (sum(best[n]) == sum(val) and best[n] < val) best[n] is None
            or sum(best[n]) < sum(val) best[n] is None best[n] best n None sum(best[n]) < sum(val) sum(best[n]) sum best[n] best n sum(val) sum val sum(best[n]) == sum(val) and best[n] < val sum(best[n]) == sum(val) sum(best[n]) sum best[n] best n sum(val) sum val best[n] < val best[n] best n val best[n] = val best[n] best n val print(''.join(sorted(''.join(str(d) * n for d, n in zip(A, best[N])), reverse=True))) print ''.join(sorted(''.join(str(d) * n for d, n in zip(A, best[N])), reverse=True)) ''.join '' join sorted(''.join(str(d) * n for d, n in zip(A, best[N])), reverse=True) sorted ''.join(str(d) * n for d, n in zip(A, best[N])) ''.join '' join str(d) * n str(d) str d n reverse=True reverse True M = map(int, input().split()) map(int, input().split()) M A = sorted(A, reverse=True) sorted(A, reverse=True) A before = n - COST[a] n - COST[a] before best = [None for _ in range(N + 1)] [None for _ in range(N + 1)] best A = list(map(int, input().split())) list(map(int, input().split())) A val = tuple(x + (1 if i == ai else 0) for i, x in enumerate(best[before])) tuple(x + (1 if i == ai else 0) for i, x in enumerate(best[before])) val N, M = map(int, input().split()) map(int, input().split()) N COST = {
    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,
} COST
N, M = map(int, input().split())
A = list(map(int, input().split()))


COST = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
}
A = sorted(A, reverse=True)

best = [None for _ in range(N + 1)]
best[0] = tuple([0] * len(A))
for n in range(N + 1):
    for ai, a in enumerate(A):
        before = n - COST[a]
        if before < 0 or best[before] is None:
            continue
        val = tuple(x + (1 if i == ai else 0) for i, x in enumerate(best[before]))
        if (
            best[n] is None
            or sum(best[n]) < sum(val)
            or (sum(best[n]) == sum(val) and best[n] < val)
        ):
            best[n] = val
print(''.join(sorted(''.join(str(d) * n for d, n in zip(A, best[N])), reverse=True)))