import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
a = list(map(int, readline().split()))
memo = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [''] * (n + 1)
for aa in a:
    if memo[aa] <= n:
        dp[memo[aa]] = max(dp[memo[aa]], str(aa))
for i in range(n):
    if dp[i] == '':
        continue
    for aa in a:
        if i + memo[aa] <= n:
            v = str(aa) + dp[i]
            if len(dp[i + memo[aa]]) < len(v):
                dp[i + memo[aa]] = v
            else:
                dp[i + memo[aa]] = max(dp[i + memo[aa]], v)
print(dp[-1]) import sys sys read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline readlines = sys.stdin.buffer.readlines readlines sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 n, m = map(int, readline().split()) n map(int, readline().split()) map int readline().split() ().split () readline split m a = list(map(int, readline().split())) a list(map(int, readline().split())) list map(int, readline().split()) map int readline().split() ().split () readline split memo = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] memo [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] 0 2 5 5 4 5 6 3 7 6 dp = [''] * (n + 1) dp [''] * (n + 1) [''] '' n + 1 n 1 for aa in a:
    if memo[aa] <= n:
        dp[memo[aa]] = max(dp[memo[aa]], str(aa)) aa a if memo[aa] <= n:
        dp[memo[aa]] = max(dp[memo[aa]], str(aa)) memo[aa] <= n memo[aa] memo aa n dp[memo[aa]] = max(dp[memo[aa]], str(aa)) dp[memo[aa]] dp memo[aa] memo aa max(dp[memo[aa]], str(aa)) max dp[memo[aa]] dp memo[aa] memo aa str(aa) str aa for i in range(n):
    if dp[i] == '':
        continue
    for aa in a:
        if i + memo[aa] <= n:
            v = str(aa) + dp[i]
            if len(dp[i + memo[aa]]) < len(v):
                dp[i + memo[aa]] = v
            else:
                dp[i + memo[aa]] = max(dp[i + memo[aa]], v) i range(n) range n if dp[i] == '':
        continue
     dp[i] == '' dp[i] dp i '' continue for aa in a:
        if i + memo[aa] <= n:
            v = str(aa) + dp[i]
            if len(dp[i + memo[aa]]) < len(v):
                dp[i + memo[aa]] = v
            else:
                dp[i + memo[aa]] = max(dp[i + memo[aa]], v) aa a if i + memo[aa] <= n:
            v = str(aa) + dp[i]
            if len(dp[i + memo[aa]]) < len(v):
                dp[i + memo[aa]] = v
            else:
                dp[i + memo[aa]] = max(dp[i + memo[aa]], v) i + memo[aa] <= n i + memo[aa] i memo[aa] memo aa n v = str(aa) + dp[i] v str(aa) + dp[i] str(aa) str aa dp[i] dp i if len(dp[i + memo[aa]]) < len(v):
                dp[i + memo[aa]] = v
            else:
                dp[i + memo[aa]] = max(dp[i + memo[aa]], v) len(dp[i + memo[aa]]) < len(v) len(dp[i + memo[aa]]) len dp[i + memo[aa]] dp i + memo[aa] i memo[aa] memo aa len(v) len v dp[i + memo[aa]] = v dp[i + memo[aa]] dp i + memo[aa] i memo[aa] memo aa v dp[i + memo[aa]] = max(dp[i + memo[aa]], v) dp[i + memo[aa]] dp i + memo[aa] i memo[aa] memo aa max(dp[i + memo[aa]], v) max dp[i + memo[aa]] dp i + memo[aa] i memo[aa] memo aa v print(dp[-1]) print dp[-1] dp -1 v = str(aa) + dp[i] str(aa) + dp[i] v m = map(int, readline().split()) map(int, readline().split()) m readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline a = list(map(int, readline().split())) list(map(int, readline().split())) a dp = [''] * (n + 1) [''] * (n + 1) dp readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines memo = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] memo read = sys.stdin.buffer.read sys.stdin.buffer.read read n, m = map(int, readline().split()) map(int, readline().split()) n
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
a = list(map(int, readline().split()))
memo = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [''] * (n + 1)
for aa in a:
    if memo[aa] <= n:
        dp[memo[aa]] = max(dp[memo[aa]], str(aa))
for i in range(n):
    if dp[i] == '':
        continue
    for aa in a:
        if i + memo[aa] <= n:
            v = str(aa) + dp[i]
            if len(dp[i + memo[aa]]) < len(v):
                dp[i + memo[aa]] = v
            else:
                dp[i + memo[aa]] = max(dp[i + memo[aa]], v)
print(dp[-1])
