N, M = map(int, input().split())
A = list(map(int, input().split()))
d = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
D = {a: d[a] for a in A}
m = min(D.values())
E = {}
for k, v in D.items():
    v -= m
    if v in E:
        E[v] = max(E[v], k)
    else:
        E[v] = k
F = sorted(E.keys(), key=lambda f: (max(0, E[f]-E[0]), f), reverse=True)
F.remove(0)
K = N // m
for k in range(K, 0, -1):
    B = [E[0]] * k
    R = N - k * m
    if not R:
        print("".join(map(str, sorted(B, reverse=True))))
        break
    def rec(r, i, j):
        if i < 0:
            return
        for f in F[j:]:
            if r == f:
                B[i] = E[f]
                print("".join(map(str, sorted(B, reverse=True))))
                exit()
            elif r > f:
                B[i], tmp = E[f], B[i]
                rec(r - f, i - 1, j)
                B[i] = tmp
            j += 1
    rec(R, k-1, 0) 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 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 a: d[a] for a in A for a in A a A for a in A a d[a] d a D = {a: d[a] for a in A} D {a: d[a] for a in A} m = min(D.values()) m min(D.values()) min D.values() D.values D values E = {} E {} for k, v in D.items():
    v -= m
    if v in E:
        E[v] = max(E[v], k)
    else:
        E[v] = k k v D.items() D.items D items v -= m v m if v in E:
        E[v] = max(E[v], k)
    else:
        E[v] = k v in E v E E[v] = max(E[v], k) E[v] E v max(E[v], k) max E[v] E v k E[v] = k E[v] E v k F = sorted(E.keys(), key=lambda f: (max(0, E[f]-E[0]), f), reverse=True) F sorted(E.keys(), key=lambda f: (max(0, E[f]-E[0]), f), reverse=True) sorted E.keys() E.keys E keys key=lambda f: (max(0, E[f]-E[0]), f) key lambda f: (max(0, E[f]-E[0]), f) (max(0, E[f]-E[0]), f) max(0, E[f]-E[0]) max 0 E[f]-E[0] E[f] E f E[0] E 0 f f reverse=True reverse True F.remove(0) F.remove F remove 0 K = N // m K N // m N m for k in range(K, 0, -1):
    B = [E[0]] * k
    R = N - k * m
    if not R:
        print("".join(map(str, sorted(B, reverse=True))))
        break
    def rec(r, i, j):
        if i < 0:
            return
        for f in F[j:]:
            if r == f:
                B[i] = E[f]
                print("".join(map(str, sorted(B, reverse=True))))
                exit()
            elif r > f:
                B[i], tmp = E[f], B[i]
                rec(r - f, i - 1, j)
                B[i] = tmp
            j += 1
    rec(R, k-1, 0) k range(K, 0, -1) range K 0 -1 B = [E[0]] * k B [E[0]] * k [E[0]] E[0] E 0 k R = N - k * m R N - k * m N k * m k m if not R:
        print("".join(map(str, sorted(B, reverse=True))))
        break
     not R R print("".join(map(str, sorted(B, reverse=True)))) print "".join(map(str, sorted(B, reverse=True))) "".join "" join map(str, sorted(B, reverse=True)) map str sorted(B, reverse=True) sorted B reverse=True reverse True break def rec(r, i, j):
        if i < 0:
            return
        for f in F[j:]:
            if r == f:
                B[i] = E[f]
                print("".join(map(str, sorted(B, reverse=True))))
                exit()
            elif r > f:
                B[i], tmp = E[f], B[i]
                rec(r - f, i - 1, j)
                B[i] = tmp
            j += 1
     rec if i < 0:
            return
         i < 0 i 0 return for f in F[j:]:
            if r == f:
                B[i] = E[f]
                print("".join(map(str, sorted(B, reverse=True))))
                exit()
            elif r > f:
                B[i], tmp = E[f], B[i]
                rec(r - f, i - 1, j)
                B[i] = tmp
            j += 1
     f F[j:] F j: j if r == f:
                B[i] = E[f]
                print("".join(map(str, sorted(B, reverse=True))))
                exit()
            elif r > f:
                B[i], tmp = E[f], B[i]
                rec(r - f, i - 1, j)
                B[i] = tmp
             r == f r f B[i] = E[f] B[i] B i E[f] E f print("".join(map(str, sorted(B, reverse=True)))) print "".join(map(str, sorted(B, reverse=True))) "".join "" join map(str, sorted(B, reverse=True)) map str sorted(B, reverse=True) sorted B reverse=True reverse True exit() exit elif r > f:
                B[i], tmp = E[f], B[i]
                rec(r - f, i - 1, j)
                B[i] = tmp
             r > f r f B[i], tmp = E[f], B[i] B[i] B i E[f] E f tmp B[i] B i rec(r - f, i - 1, j) rec r - f r f i - 1 i 1 j B[i] = tmp B[i] B i tmp j += 1 j 1 r r i i j j rec(R, k-1, 0) rec R k-1 k 1 0 B = [E[0]] * k [E[0]] * k B M = map(int, input().split()) map(int, input().split()) M v -= m m v R = N - k * m N - k * m R E = {} {} E m = min(D.values()) min(D.values()) m def rec(r, i, j):
        if i < 0:
            return
        for f in F[j:]:
            if r == f:
                B[i] = E[f]
                print("".join(map(str, sorted(B, reverse=True))))
                exit()
            elif r > f:
                B[i], tmp = E[f], B[i]
                rec(r - f, i - 1, j)
                B[i] = tmp
            j += 1
     def rec(r, i, j):
        if i < 0:
            return
        for f in F[j:]:
            if r == f:
                B[i] = E[f]
                print("".join(map(str, sorted(B, reverse=True))))
                exit()
            elif r > f:
                B[i], tmp = E[f], B[i]
                rec(r - f, i - 1, j)
                B[i] = tmp
            j += 1
     rec F = sorted(E.keys(), key=lambda f: (max(0, E[f]-E[0]), f), reverse=True) sorted(E.keys(), key=lambda f: (max(0, E[f]-E[0]), f), reverse=True) F A = list(map(int, input().split())) list(map(int, input().split())) A 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 K = N // m N // m K D = {a: d[a] for a in A} {a: d[a] for a in A} D N, M = map(int, input().split()) map(int, input().split()) N
N, M = map(int, input().split())
A = list(map(int, input().split()))
d = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
D = {a: d[a] for a in A}
m = min(D.values())
E = {}
for k, v in D.items():
    v -= m
    if v in E:
        E[v] = max(E[v], k)
    else:
        E[v] = k
F = sorted(E.keys(), key=lambda f: (max(0, E[f]-E[0]), f), reverse=True)
F.remove(0)
K = N // m
for k in range(K, 0, -1):
    B = [E[0]] * k
    R = N - k * m
    if not R:
        print("".join(map(str, sorted(B, reverse=True))))
        break
    def rec(r, i, j):
        if i < 0:
            return
        for f in F[j:]:
            if r == f:
                B[i] = E[f]
                print("".join(map(str, sorted(B, reverse=True))))
                exit()
            elif r > f:
                B[i], tmp = E[f], B[i]
                rec(r - f, i - 1, j)
                B[i] = tmp
            j += 1
    rec(R, k-1, 0)