N,_ = map(int, input().split())
A = [int(i) for i in input().split()]

INF = "-"

def chmax(a:str,b:str):
    if a == INF: return b
    elif len(a) < len(b): return b
    elif len(a) == len(a):
        if a < b: return b
    return a

# 数字 : 必要なマッチの本数
cnt = dict(zip(range(1,10), [2,5,5,4,5,6,3,7,6]))

# dp[i]: マッチをi本使って作れる数値の最大値
dp = [INF] * (10 ** 5)

# 初期条件
dp[0] = ""

# 配るDP
for i in range(N):
    if dp[i] == INF: continue
    for a in A:
        dp[i + cnt[a]] = chmax(dp[i + cnt[a]], dp[i] + chr(ord("0") + a))

print(dp[N]) N,_ = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split _ int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i A = [int(i) for i in input().split()] A [int(i) for i in input().split()] INF = "-" INF "-" def chmax(a:str,b:str):
    if a == INF: return b
    elif len(a) < len(b): return b
    elif len(a) == len(a):
        if a < b: return b
    return a

# 数字 : 必要なマッチの本数 chmax if a == INF: return b
    elif len(a) < len(b): return b
    elif len(a) == len(a):
        if a < b: return b
     a == INF a INF elif len(a) < len(b): return b
     len(a) < len(b) len(a) len a len(b) len b elif len(a) == len(a):
        if a < b: return b
     len(a) == len(a) len(a) len a len(a) len a if a < b: return b
     a < b a b return a a a:str a b:str b cnt = dict(zip(range(1,10), [2,5,5,4,5,6,3,7,6])) cnt dict(zip(range(1,10), [2,5,5,4,5,6,3,7,6])) dict zip(range(1,10), [2,5,5,4,5,6,3,7,6]) zip range(1,10) range 1 10 [2,5,5,4,5,6,3,7,6] 2 5 5 4 5 6 3 7 6 dp = [INF] * (10 ** 5) dp [INF] * (10 ** 5) [INF] INF 10 ** 5 10 5 dp[0] = "" dp[0] dp 0 "" for i in range(N):
    if dp[i] == INF: continue
    for a in A:
        dp[i + cnt[a]] = chmax(dp[i + cnt[a]], dp[i] + chr(ord("0") + a)) i range(N) range N if dp[i] == INF: continue
     dp[i] == INF dp[i] dp i INF for a in A:
        dp[i + cnt[a]] = chmax(dp[i + cnt[a]], dp[i] + chr(ord("0") + a)) a A dp[i + cnt[a]] = chmax(dp[i + cnt[a]], dp[i] + chr(ord("0") + a)) dp[i + cnt[a]] dp i + cnt[a] i cnt[a] cnt a chmax(dp[i + cnt[a]], dp[i] + chr(ord("0") + a)) chmax dp[i + cnt[a]] dp i + cnt[a] i cnt[a] cnt a dp[i] + chr(ord("0") + a) dp[i] dp i chr(ord("0") + a) chr ord("0") + a ord("0") ord "0" a print(dp[N]) print dp[N] dp N N,_ = map(int, input().split()) map(int, input().split()) N INF = "-" "-" INF dp = [INF] * (10 ** 5) [INF] * (10 ** 5) dp cnt = dict(zip(range(1,10), [2,5,5,4,5,6,3,7,6])) dict(zip(range(1,10), [2,5,5,4,5,6,3,7,6])) cnt _ = map(int, input().split()) map(int, input().split()) _ A = [int(i) for i in input().split()] [int(i) for i in input().split()] A def chmax(a:str,b:str):
    if a == INF: return b
    elif len(a) < len(b): return b
    elif len(a) == len(a):
        if a < b: return b
    return a

# 数字 : 必要なマッチの本数 def chmax(a:str,b:str):
    if a == INF: return b
    elif len(a) < len(b): return b
    elif len(a) == len(a):
        if a < b: return b
    return a

# 数字 : 必要なマッチの本数 chmax
N,_ = map(int, input().split())
A = [int(i) for i in input().split()]

INF = "-"

def chmax(a:str,b:str):
    if a == INF: return b
    elif len(a) < len(b): return b
    elif len(a) == len(a):
        if a < b: return b
    return a

# 数字 : 必要なマッチの本数
cnt = dict(zip(range(1,10), [2,5,5,4,5,6,3,7,6]))

# dp[i]: マッチをi本使って作れる数値の最大値
dp = [INF] * (10 ** 5)

# 初期条件
dp[0] = ""

# 配るDP
for i in range(N):
    if dp[i] == INF: continue
    for a in A:
        dp[i + cnt[a]] = chmax(dp[i + cnt[a]], dp[i] + chr(ord("0") + a))

print(dp[N])