import resource
import sys
sys.setrecursionlimit(20000)
f = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
n, m = map(int, input().split())
a = list(map(int, input().split()))

memo = ["-1"] * 10100


def MAX(x, y):
    if y[0] != '#' and (x == "#" or len(x) < len(y) or (len(x) == len(y) and x < y)):
        return y
    else:
        return x


def dp(i):
    # i本のマッチを使って作れる最大の整数
    if i < 0:
        return "#"

    if memo[i] != "-1":
        return memo[i]

    if i == 0:
        return ""

    ret = "#"
    for x in a:
        ret = MAX(ret, dp(i - f[x]) + str(x))
    memo[i] = ret
    return ret


print(dp(n)) import resource resource import sys sys sys.setrecursionlimit(20000) sys.setrecursionlimit sys setrecursionlimit 20000 f = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] f [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] 0 2 5 5 4 5 6 3 7 6 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 memo = ["-1"] * 10100 memo ["-1"] * 10100 ["-1"] "-1" 10100 def MAX(x, y):
    if y[0] != '#' and (x == "#" or len(x) < len(y) or (len(x) == len(y) and x < y)):
        return y
    else:
        return x MAX if y[0] != '#' and (x == "#" or len(x) < len(y) or (len(x) == len(y) and x < y)):
        return y
    else:
        return x y[0] != '#' and (x == "#" or len(x) < len(y) or (len(x) == len(y) and x < y)) y[0] != '#' y[0] y 0 '#' x == "#" or len(x) < len(y) or (len(x) == len(y) and x < y) x == "#" or len(x) < len(y) x == "#" x "#" len(x) < len(y) len(x) len x len(y) len y len(x) == len(y) and x < y len(x) == len(y) len(x) len x len(y) len y x < y x y return y y return x x x x y y def dp(i):
    # i本のマッチを使って作れる最大の整数
    if i < 0:
        return "#"

    if memo[i] != "-1":
        return memo[i]

    if i == 0:
        return ""

    ret = "#"
    for x in a:
        ret = MAX(ret, dp(i - f[x]) + str(x))
    memo[i] = ret
    return ret dp if i < 0:
        return "#"

     i < 0 i 0 return "#" "#" if memo[i] != "-1":
        return memo[i]

     memo[i] != "-1" memo[i] memo i "-1" return memo[i] memo[i] memo i if i == 0:
        return ""

     i == 0 i 0 return "" "" ret = "#" ret "#" for x in a:
        ret = MAX(ret, dp(i - f[x]) + str(x))
     x a ret = MAX(ret, dp(i - f[x]) + str(x)) ret MAX(ret, dp(i - f[x]) + str(x)) MAX ret dp(i - f[x]) + str(x) dp(i - f[x]) dp i - f[x] i f[x] f x str(x) str x memo[i] = ret memo[i] memo i ret return ret ret i i print(dp(n)) print dp(n) dp n m = map(int, input().split()) map(int, input().split()) m a = list(map(int, input().split())) list(map(int, input().split())) a def MAX(x, y):
    if y[0] != '#' and (x == "#" or len(x) < len(y) or (len(x) == len(y) and x < y)):
        return y
    else:
        return x def MAX(x, y):
    if y[0] != '#' and (x == "#" or len(x) < len(y) or (len(x) == len(y) and x < y)):
        return y
    else:
        return x MAX n, m = map(int, input().split()) map(int, input().split()) n f = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] f memo = ["-1"] * 10100 ["-1"] * 10100 memo def dp(i):
    # i本のマッチを使って作れる最大の整数
    if i < 0:
        return "#"

    if memo[i] != "-1":
        return memo[i]

    if i == 0:
        return ""

    ret = "#"
    for x in a:
        ret = MAX(ret, dp(i - f[x]) + str(x))
    memo[i] = ret
    return ret def dp(i):
    # i本のマッチを使って作れる最大の整数
    if i < 0:
        return "#"

    if memo[i] != "-1":
        return memo[i]

    if i == 0:
        return ""

    ret = "#"
    for x in a:
        ret = MAX(ret, dp(i - f[x]) + str(x))
    memo[i] = ret
    return ret dp
import resource
import sys
sys.setrecursionlimit(20000)
f = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
n, m = map(int, input().split())
a = list(map(int, input().split()))

memo = ["-1"] * 10100


def MAX(x, y):
    if y[0] != '#' and (x == "#" or len(x) < len(y) or (len(x) == len(y) and x < y)):
        return y
    else:
        return x


def dp(i):
    # i本のマッチを使って作れる最大の整数
    if i < 0:
        return "#"

    if memo[i] != "-1":
        return memo[i]

    if i == 0:
        return ""

    ret = "#"
    for x in a:
        ret = MAX(ret, dp(i - f[x]) + str(x))
    memo[i] = ret
    return ret


print(dp(n))
