import sys

sys.setrecursionlimit(10000000)
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue

# import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    A = il()
    matches = [2, 5, 5, 4, 5, 6, 3, 7, 6]
    dict = {i + 1: matches[i] for i in range(9)}
    dp = [-1] * (N + 1)
    dp[0] = 0

    for n in range(N + 1):
        for a in A:
            if n + dict[a] <= N:
                dp[n + dict[a]] = max(dp[n + dict[a]], dp[n] * 10 + a)
    print(dp[N])


if __name__ == '__main__':
    main() import sys sys sys.setrecursionlimit(10000000) sys.setrecursionlimit sys setrecursionlimit 10000000 import os os import math math import bisect bisect import collections collections import itertools itertools import heapq heapq import re re import queue queue ii = lambda: int(sys.stdin.buffer.readline().rstrip()) ii lambda: int(sys.stdin.buffer.readline().rstrip()) int(sys.stdin.buffer.readline().rstrip()) int sys.stdin.buffer.readline().rstrip() sys.stdin.buffer.readline().rstrip sys.stdin.buffer.readline() sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline rstrip il = lambda: list(map(int, sys.stdin.buffer.readline().split())) il lambda: list(map(int, sys.stdin.buffer.readline().split())) list(map(int, sys.stdin.buffer.readline().split())) list map(int, sys.stdin.buffer.readline().split()) map int sys.stdin.buffer.readline().split() sys.stdin.buffer.readline().split sys.stdin.buffer.readline() sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline split fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) fl lambda: list(map(float, sys.stdin.buffer.readline().split())) list(map(float, sys.stdin.buffer.readline().split())) list map(float, sys.stdin.buffer.readline().split()) map float sys.stdin.buffer.readline().split() sys.stdin.buffer.readline().split sys.stdin.buffer.readline() sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline split int(sys.stdin.buffer.readline().rstrip()) for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) int(sys.stdin.buffer.readline().rstrip()) int sys.stdin.buffer.readline().rstrip() sys.stdin.buffer.readline().rstrip sys.stdin.buffer.readline() sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline rstrip iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iln lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] n iss = lambda: sys.stdin.buffer.readline().decode().rstrip() iss lambda: sys.stdin.buffer.readline().decode().rstrip() sys.stdin.buffer.readline().decode().rstrip() sys.stdin.buffer.readline().decode().rstrip sys.stdin.buffer.readline().decode() sys.stdin.buffer.readline().decode sys.stdin.buffer.readline() sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline decode rstrip sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) sl lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) list(map(str, sys.stdin.buffer.readline().decode().split())) list map(str, sys.stdin.buffer.readline().decode().split()) map str sys.stdin.buffer.readline().decode().split() sys.stdin.buffer.readline().decode().split sys.stdin.buffer.readline().decode() sys.stdin.buffer.readline().decode sys.stdin.buffer.readline() sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline decode split sys.stdin.buffer.readline().decode().rstrip() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) sys.stdin.buffer.readline().decode().rstrip() sys.stdin.buffer.readline().decode().rstrip sys.stdin.buffer.readline().decode() sys.stdin.buffer.readline().decode sys.stdin.buffer.readline() sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline decode rstrip isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] isn lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] n lcm = lambda x, y: (x * y) // math.gcd(x, y) lcm lambda x, y: (x * y) // math.gcd(x, y) (x * y) // math.gcd(x, y) x * y x y math.gcd(x, y) math.gcd math gcd x y x y MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 MAX = float('inf') MAX float('inf') float 'inf' def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    A = il()
    matches = [2, 5, 5, 4, 5, 6, 3, 7, 6]
    dict = {i + 1: matches[i] for i in range(9)}
    dp = [-1] * (N + 1)
    dp[0] = 0

    for n in range(N + 1):
        for a in A:
            if n + dict[a] <= N:
                dp[n + dict[a]] = max(dp[n + dict[a]], dp[n] * 10 + a)
    print(dp[N]) main if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

     os.getenv("LOCAL") os.getenv os getenv "LOCAL" sys.stdin = open("input.txt", "r") sys.stdin sys stdin open("input.txt", "r") open "input.txt" "r" N, M = il() N il() il M A = il() A il() il matches = [2, 5, 5, 4, 5, 6, 3, 7, 6] matches [2, 5, 5, 4, 5, 6, 3, 7, 6] 2 5 5 4 5 6 3 7 6 i + 1: matches[i] for i in range(9) for i in range(9) i range(9) range 9 for i in range(9) i + 1 i 1 matches[i] matches i dict = {i + 1: matches[i] for i in range(9)} dict {i + 1: matches[i] for i in range(9)} dp = [-1] * (N + 1) dp [-1] * (N + 1) [-1] -1 N + 1 N 1 dp[0] = 0 dp[0] dp 0 0 for n in range(N + 1):
        for a in A:
            if n + dict[a] <= N:
                dp[n + dict[a]] = max(dp[n + dict[a]], dp[n] * 10 + a)
     n range(N + 1) range N + 1 N 1 for a in A:
            if n + dict[a] <= N:
                dp[n + dict[a]] = max(dp[n + dict[a]], dp[n] * 10 + a)
     a A if n + dict[a] <= N:
                dp[n + dict[a]] = max(dp[n + dict[a]], dp[n] * 10 + a)
     n + dict[a] <= N n + dict[a] n dict[a] dict a N dp[n + dict[a]] = max(dp[n + dict[a]], dp[n] * 10 + a) dp[n + dict[a]] dp n + dict[a] n dict[a] dict a max(dp[n + dict[a]], dp[n] * 10 + a) max dp[n + dict[a]] dp n + dict[a] n dict[a] dict a dp[n] * 10 + a dp[n] * 10 dp[n] dp n 10 a print(dp[N]) print dp[N] dp N if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main iss = lambda: sys.stdin.buffer.readline().decode().rstrip() lambda: sys.stdin.buffer.readline().decode().rstrip() iss isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] isn fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) lambda: list(map(float, sys.stdin.buffer.readline().split())) fl sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) sl MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD ii = lambda: int(sys.stdin.buffer.readline().rstrip()) lambda: int(sys.stdin.buffer.readline().rstrip()) ii il = lambda: list(map(int, sys.stdin.buffer.readline().split())) lambda: list(map(int, sys.stdin.buffer.readline().split())) il def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    A = il()
    matches = [2, 5, 5, 4, 5, 6, 3, 7, 6]
    dict = {i + 1: matches[i] for i in range(9)}
    dp = [-1] * (N + 1)
    dp[0] = 0

    for n in range(N + 1):
        for a in A:
            if n + dict[a] <= N:
                dp[n + dict[a]] = max(dp[n + dict[a]], dp[n] * 10 + a)
    print(dp[N]) def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    A = il()
    matches = [2, 5, 5, 4, 5, 6, 3, 7, 6]
    dict = {i + 1: matches[i] for i in range(9)}
    dp = [-1] * (N + 1)
    dp[0] = 0

    for n in range(N + 1):
        for a in A:
            if n + dict[a] <= N:
                dp[n + dict[a]] = max(dp[n + dict[a]], dp[n] * 10 + a)
    print(dp[N]) main MAX = float('inf') float('inf') MAX iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iln lcm = lambda x, y: (x * y) // math.gcd(x, y) lambda x, y: (x * y) // math.gcd(x, y) lcm
import sys

sys.setrecursionlimit(10000000)
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue

# import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    A = il()
    matches = [2, 5, 5, 4, 5, 6, 3, 7, 6]
    dict = {i + 1: matches[i] for i in range(9)}
    dp = [-1] * (N + 1)
    dp[0] = 0

    for n in range(N + 1):
        for a in A:
            if n + dict[a] <= N:
                dp[n + dict[a]] = max(dp[n + dict[a]], dp[n] * 10 + a)
    print(dp[N])


if __name__ == '__main__':
    main()
