n, _ = list(map(int, input().split()))
as_ = sorted(map(int, input().split()))

match = [None, 2, 5, 5, 4, 5, 6, 3, 7, 6]

dp = [[] for i in range(n + 1)]

def gt(xs, ys):
    m = len(xs)
    n = len(ys)
    if m > n:
        return True
    if m < n:
        return False
    else:
        for i in range(m):
            if xs[i] > ys[i]:
                return True
            elif xs[i] == ys[i]:
                continue
            else:
                return False
    return False

for i in range(1, n + 1):
    ds_max = dp[i - 1]
    for a in as_:
        b = match[a]
        if 0 <= i - b <= n:
            ds = dp[i - b] + [a]
            ds.sort
            ds.reverse
            if gt(ds, ds_max):
                ds_max = ds
    dp[i] = ds_max

ans = dp[i]

# for i in range(n, -1, -1):
#   ans[i] =

print("".join(list(map(str, dp[n]))))