#coding: utf-8
import math
import heapq
import bisect
import numpy as np
#from scipy.misc import comb

number = [0,2,5,5,4,5,6,3,7,6]

N,M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

dp = [-1]*(N+1)
dp[0] = 0
for i in range(N+1):
    for a in A:
        if i-number[a] >= 0:
            if dp[i-number[a]] >= 0:
                dp[i] = max(dp[i], dp[i-number[a]]*10+a)

print(dp[N]) import math math import heapq heapq import bisect bisect import numpy as np numpy number = [0,2,5,5,4,5,6,3,7,6] number [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 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 dp = [-1]*(N+1) dp [-1]*(N+1) [-1] -1 N+1 N 1 dp[0] = 0 dp[0] dp 0 0 for i in range(N+1):
    for a in A:
        if i-number[a] >= 0:
            if dp[i-number[a]] >= 0:
                dp[i] = max(dp[i], dp[i-number[a]]*10+a) i range(N+1) range N+1 N 1 for a in A:
        if i-number[a] >= 0:
            if dp[i-number[a]] >= 0:
                dp[i] = max(dp[i], dp[i-number[a]]*10+a) a A if i-number[a] >= 0:
            if dp[i-number[a]] >= 0:
                dp[i] = max(dp[i], dp[i-number[a]]*10+a) i-number[a] >= 0 i-number[a] i number[a] number a 0 if dp[i-number[a]] >= 0:
                dp[i] = max(dp[i], dp[i-number[a]]*10+a) dp[i-number[a]] >= 0 dp[i-number[a]] dp i-number[a] i number[a] number a 0 dp[i] = max(dp[i], dp[i-number[a]]*10+a) dp[i] dp i max(dp[i], dp[i-number[a]]*10+a) max dp[i] dp i dp[i-number[a]]*10+a dp[i-number[a]]*10 dp[i-number[a]] dp i-number[a] i number[a] number a 10 a print(dp[N]) print dp[N] dp N number = [0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] number N,M = map(int, input().split()) map(int, input().split()) N dp = [-1]*(N+1) [-1]*(N+1) dp M = map(int, input().split()) map(int, input().split()) M A = list(map(int, input().split())) list(map(int, input().split())) A
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
#from scipy.misc import comb

number = [0,2,5,5,4,5,6,3,7,6]

N,M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

dp = [-1]*(N+1)
dp[0] = 0
for i in range(N+1):
    for a in A:
        if i-number[a] >= 0:
            if dp[i-number[a]] >= 0:
                dp[i] = max(dp[i], dp[i-number[a]]*10+a)

print(dp[N])