N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
nums = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-10**18]*(N+1)
dp[0] = 0

for i in range(N):
    for Ai in A:
        if i+nums[Ai]<=N:
            dp[i+nums[Ai]] = max(dp[i+nums[Ai]], dp[i]+1)

ans = []
now = N

for i in range(dp[N]):
    for Ai in A:
        if now-nums[Ai]>=0 and dp[now-nums[Ai]]==dp[N]-i-1:
            now -= nums[Ai]
            ans.append(str(Ai))
            break

print(''.join(ans)) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M A = list(map(int, input().split())) A list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split A.sort(reverse=True) A.sort A sort reverse=True reverse True nums = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] nums [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] 0 2 5 5 4 5 6 3 7 6 dp = [-10**18]*(N+1) dp [-10**18]*(N+1) [-10**18] -10**18 -10 18 N+1 N 1 dp[0] = 0 dp[0] dp 0 0 for i in range(N):
    for Ai in A:
        if i+nums[Ai]<=N:
            dp[i+nums[Ai]] = max(dp[i+nums[Ai]], dp[i]+1) i range(N) range N for Ai in A:
        if i+nums[Ai]<=N:
            dp[i+nums[Ai]] = max(dp[i+nums[Ai]], dp[i]+1) Ai A if i+nums[Ai]<=N:
            dp[i+nums[Ai]] = max(dp[i+nums[Ai]], dp[i]+1) i+nums[Ai]<=N i+nums[Ai] i nums[Ai] nums Ai N dp[i+nums[Ai]] = max(dp[i+nums[Ai]], dp[i]+1) dp[i+nums[Ai]] dp i+nums[Ai] i nums[Ai] nums Ai max(dp[i+nums[Ai]], dp[i]+1) max dp[i+nums[Ai]] dp i+nums[Ai] i nums[Ai] nums Ai dp[i]+1 dp[i] dp i 1 ans = [] ans [] now = N now N for i in range(dp[N]):
    for Ai in A:
        if now-nums[Ai]>=0 and dp[now-nums[Ai]]==dp[N]-i-1:
            now -= nums[Ai]
            ans.append(str(Ai))
            break i range(dp[N]) range dp[N] dp N for Ai in A:
        if now-nums[Ai]>=0 and dp[now-nums[Ai]]==dp[N]-i-1:
            now -= nums[Ai]
            ans.append(str(Ai))
            break Ai A if now-nums[Ai]>=0 and dp[now-nums[Ai]]==dp[N]-i-1:
            now -= nums[Ai]
            ans.append(str(Ai))
            break now-nums[Ai]>=0 and dp[now-nums[Ai]]==dp[N]-i-1 now-nums[Ai]>=0 now-nums[Ai] now nums[Ai] nums Ai 0 dp[now-nums[Ai]]==dp[N]-i-1 dp[now-nums[Ai]] dp now-nums[Ai] now nums[Ai] nums Ai dp[N]-i-1 dp[N]-i dp[N] dp N i 1 now -= nums[Ai] now nums[Ai] nums Ai ans.append(str(Ai)) ans.append ans append str(Ai) str Ai break print(''.join(ans)) print ''.join(ans) ''.join '' join ans ans = [] [] ans dp = [-10**18]*(N+1) [-10**18]*(N+1) dp now -= nums[Ai] nums[Ai] now nums = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] nums now = N N now N, M = map(int, input().split()) map(int, input().split()) N M = map(int, input().split()) map(int, input().split()) M A = list(map(int, input().split())) list(map(int, input().split())) A
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
nums = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-10**18]*(N+1)
dp[0] = 0

for i in range(N):
    for Ai in A:
        if i+nums[Ai]<=N:
            dp[i+nums[Ai]] = max(dp[i+nums[Ai]], dp[i]+1)

ans = []
now = N

for i in range(dp[N]):
    for Ai in A:
        if now-nums[Ai]>=0 and dp[now-nums[Ai]]==dp[N]-i-1:
            now -= nums[Ai]
            ans.append(str(Ai))
            break

print(''.join(ans))