Q = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
}
 
N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
 
# 桁数の最大
dp = [-1] * (N + 1)
dp[0] = 0
 
for a in A:
    for i in range(Q[a], N + 1):
        if dp[i - Q[a]] >= 0:
            dp[i] = max(dp[i], dp[i - Q[a]] + 1)
            #print(dp)
 
# 整数の復元
ans = ''
 
# 大きな数から試す
A.sort(reverse=True)
 
i = N
while i:
    for a in A:
        if i - Q[a] >= 0 and dp[i - Q[a]] == dp[i] - 1:
            ans += str(a)
            i -= Q[a]
            break
 
print(ans) Q = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
} Q {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
} 1 1 2 2 2 5 3 3 5 4 4 4 5 5 5 6 6 6 7 7 3 8 8 7 9 9 6 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()] dp = [-1] * (N + 1) dp [-1] * (N + 1) [-1] -1 N + 1 N 1 dp[0] = 0 dp[0] dp 0 0 for a in A:
    for i in range(Q[a], N + 1):
        if dp[i - Q[a]] >= 0:
            dp[i] = max(dp[i], dp[i - Q[a]] + 1)
            #print(dp)
 
# 整数の復元 a A for i in range(Q[a], N + 1):
        if dp[i - Q[a]] >= 0:
            dp[i] = max(dp[i], dp[i - Q[a]] + 1)
            #print(dp)
 
# 整数の復元 i range(Q[a], N + 1) range Q[a] Q a N + 1 N 1 if dp[i - Q[a]] >= 0:
            dp[i] = max(dp[i], dp[i - Q[a]] + 1)
            #print(dp)
 
# 整数の復元 dp[i - Q[a]] >= 0 dp[i - Q[a]] dp i - Q[a] i Q[a] Q a 0 dp[i] = max(dp[i], dp[i - Q[a]] + 1) dp[i] dp i max(dp[i], dp[i - Q[a]] + 1) max dp[i] dp i dp[i - Q[a]] + 1 dp[i - Q[a]] dp i - Q[a] i Q[a] Q a 1 ans = '' ans '' A.sort(reverse=True) A.sort A sort reverse=True reverse True i = N i N while i:
    for a in A:
        if i - Q[a] >= 0 and dp[i - Q[a]] == dp[i] - 1:
            ans += str(a)
            i -= Q[a]
            break
  i for a in A:
        if i - Q[a] >= 0 and dp[i - Q[a]] == dp[i] - 1:
            ans += str(a)
            i -= Q[a]
            break
  a A if i - Q[a] >= 0 and dp[i - Q[a]] == dp[i] - 1:
            ans += str(a)
            i -= Q[a]
            break
  i - Q[a] >= 0 and dp[i - Q[a]] == dp[i] - 1 i - Q[a] >= 0 i - Q[a] i Q[a] Q a 0 dp[i - Q[a]] == dp[i] - 1 dp[i - Q[a]] dp i - Q[a] i Q[a] Q a dp[i] - 1 dp[i] dp i 1 ans += str(a) ans str(a) str a i -= Q[a] i Q[a] Q a break print(ans) print ans A = [int(x) for x in input().split()] [int(x) for x in input().split()] A ans += str(a) str(a) ans N, M = [int(x) for x in input().split()] [int(x) for x in input().split()] N i = N N i Q = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
} {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
} Q dp = [-1] * (N + 1) [-1] * (N + 1) dp ans = '' '' ans M = [int(x) for x in input().split()] [int(x) for x in input().split()] M i -= Q[a] Q[a] i
Q = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
}
 
N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
 
# 桁数の最大
dp = [-1] * (N + 1)
dp[0] = 0
 
for a in A:
    for i in range(Q[a], N + 1):
        if dp[i - Q[a]] >= 0:
            dp[i] = max(dp[i], dp[i - Q[a]] + 1)
            #print(dp)
 
# 整数の復元
ans = ''
 
# 大きな数から試す
A.sort(reverse=True)
 
i = N
while i:
    for a in A:
        if i - Q[a] >= 0 and dp[i - Q[a]] == dp[i] - 1:
            ans += str(a)
            i -= Q[a]
            break
 
print(ans)