N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

# argsは数を文字列で表したリスト
# 一番大きい数を文字列として出力
def maxnum(*args):
    maxn = args[0]
    for i in range(1, len(args)):
        if len(maxn) != len(args[i]):
            if len(args[i]) > len(maxn):
                maxn = args[i]
        else:
            maxn = max(maxn, args[i])
    return maxn


# 数字0〜9を作るのに必要なマッチ棒の数
nmatch = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]

dp = [""] + [None] * N
for i in range(1, N + 1):
    maxn = ""
    for a in A:
        if i - nmatch[a] >= 0 and dp[i - nmatch[a]] != None:
            maxn = maxnum(maxn, dp[i - nmatch[a]] + str(a), str(a) + dp[i - nmatch[a]])
            dp[i] = maxn

print(dp[N]) int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x N, M = [int(x) for x in input().split()] N [int(x) for x in input().split()] M int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x A = [int(x) for x in input().split()] A [int(x) for x in input().split()] def maxnum(*args):
    maxn = args[0]
    for i in range(1, len(args)):
        if len(maxn) != len(args[i]):
            if len(args[i]) > len(maxn):
                maxn = args[i]
        else:
            maxn = max(maxn, args[i])
    return maxn


# 数字0〜9を作るのに必要なマッチ棒の数 maxnum maxn = args[0] maxn args[0] args 0 for i in range(1, len(args)):
        if len(maxn) != len(args[i]):
            if len(args[i]) > len(maxn):
                maxn = args[i]
        else:
            maxn = max(maxn, args[i])
     i range(1, len(args)) range 1 len(args) len args if len(maxn) != len(args[i]):
            if len(args[i]) > len(maxn):
                maxn = args[i]
        else:
            maxn = max(maxn, args[i])
     len(maxn) != len(args[i]) len(maxn) len maxn len(args[i]) len args[i] args i if len(args[i]) > len(maxn):
                maxn = args[i]
         len(args[i]) > len(maxn) len(args[i]) len args[i] args i len(maxn) len maxn maxn = args[i] maxn args[i] args i maxn = max(maxn, args[i]) maxn max(maxn, args[i]) max maxn args[i] args i return maxn maxn *args nmatch = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6] nmatch [6, 2, 5, 5, 4, 5, 6, 3, 7, 6] 6 2 5 5 4 5 6 3 7 6 dp = [""] + [None] * N dp [""] + [None] * N [""] "" [None] * N [None] None N for i in range(1, N + 1):
    maxn = ""
    for a in A:
        if i - nmatch[a] >= 0 and dp[i - nmatch[a]] != None:
            maxn = maxnum(maxn, dp[i - nmatch[a]] + str(a), str(a) + dp[i - nmatch[a]])
            dp[i] = maxn i range(1, N + 1) range 1 N + 1 N 1 maxn = "" maxn "" for a in A:
        if i - nmatch[a] >= 0 and dp[i - nmatch[a]] != None:
            maxn = maxnum(maxn, dp[i - nmatch[a]] + str(a), str(a) + dp[i - nmatch[a]])
            dp[i] = maxn a A if i - nmatch[a] >= 0 and dp[i - nmatch[a]] != None:
            maxn = maxnum(maxn, dp[i - nmatch[a]] + str(a), str(a) + dp[i - nmatch[a]])
            dp[i] = maxn i - nmatch[a] >= 0 and dp[i - nmatch[a]] != None i - nmatch[a] >= 0 i - nmatch[a] i nmatch[a] nmatch a 0 dp[i - nmatch[a]] != None dp[i - nmatch[a]] dp i - nmatch[a] i nmatch[a] nmatch a None maxn = maxnum(maxn, dp[i - nmatch[a]] + str(a), str(a) + dp[i - nmatch[a]]) maxn maxnum(maxn, dp[i - nmatch[a]] + str(a), str(a) + dp[i - nmatch[a]]) maxnum maxn dp[i - nmatch[a]] + str(a) dp[i - nmatch[a]] dp i - nmatch[a] i nmatch[a] nmatch a str(a) str a str(a) + dp[i - nmatch[a]] str(a) str a dp[i - nmatch[a]] dp i - nmatch[a] i nmatch[a] nmatch a dp[i] = maxn dp[i] dp i maxn print(dp[N]) print dp[N] dp N def maxnum(*args):
    maxn = args[0]
    for i in range(1, len(args)):
        if len(maxn) != len(args[i]):
            if len(args[i]) > len(maxn):
                maxn = args[i]
        else:
            maxn = max(maxn, args[i])
    return maxn


# 数字0〜9を作るのに必要なマッチ棒の数 def maxnum(*args):
    maxn = args[0]
    for i in range(1, len(args)):
        if len(maxn) != len(args[i]):
            if len(args[i]) > len(maxn):
                maxn = args[i]
        else:
            maxn = max(maxn, args[i])
    return maxn


# 数字0〜9を作るのに必要なマッチ棒の数 maxnum M = [int(x) for x in input().split()] [int(x) for x in input().split()] M nmatch = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6] [6, 2, 5, 5, 4, 5, 6, 3, 7, 6] nmatch dp = [""] + [None] * N [""] + [None] * N dp maxn = maxnum(maxn, dp[i - nmatch[a]] + str(a), str(a) + dp[i - nmatch[a]]) maxnum(maxn, dp[i - nmatch[a]] + str(a), str(a) + dp[i - nmatch[a]]) maxn A = [int(x) for x in input().split()] [int(x) for x in input().split()] A maxn = "" "" maxn N, M = [int(x) for x in input().split()] [int(x) for x in input().split()] N
N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

# argsは数を文字列で表したリスト
# 一番大きい数を文字列として出力
def maxnum(*args):
    maxn = args[0]
    for i in range(1, len(args)):
        if len(maxn) != len(args[i]):
            if len(args[i]) > len(maxn):
                maxn = args[i]
        else:
            maxn = max(maxn, args[i])
    return maxn


# 数字0〜9を作るのに必要なマッチ棒の数
nmatch = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]

dp = [""] + [None] * N
for i in range(1, N + 1):
    maxn = ""
    for a in A:
        if i - nmatch[a] >= 0 and dp[i - nmatch[a]] != None:
            maxn = maxnum(maxn, dp[i - nmatch[a]] + str(a), str(a) + dp[i - nmatch[a]])
            dp[i] = maxn

print(dp[N])
