from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
a = sorted(inpl(), reverse = True)
b = [0,2,5,5,4,5,6,3,7,6]
dp = [0] * (n+1)

for i in a:
    w,v = b[i],i
    for j in range(n+1):
        if j < w:
            continue
        if j%w == 0 or dp[j-w]:
            dp[j] = max(dp[j], dp[j-w]*10 + v)
    # print(dp)
print(dp[-1]) from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,fractions,pprint sys bisect math itertools fractions pprint sys.setrecursionlimit(10**8) sys.setrecursionlimit sys setrecursionlimit 10**8 10 8 mod = 10**9+7 mod 10**9+7 10**9 10 9 7 INF = float('inf') INF float('inf') float 'inf' def inp(): return int(sys.stdin.readline()) inp def inpl(): return list(map(int, sys.stdin.readline().split())) inpl n,m = inpl() n inpl() inpl m a = sorted(inpl(), reverse = True) a sorted(inpl(), reverse = True) sorted inpl() inpl reverse = True reverse True b = [0,2,5,5,4,5,6,3,7,6] b [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 dp = [0] * (n+1) dp [0] * (n+1) [0] 0 n+1 n 1 for i in a:
    w,v = b[i],i
    for j in range(n+1):
        if j < w:
            continue
        if j%w == 0 or dp[j-w]:
            dp[j] = max(dp[j], dp[j-w]*10 + v)
    # print(dp) i a w,v = b[i],i w b[i] b i v i for j in range(n+1):
        if j < w:
            continue
        if j%w == 0 or dp[j-w]:
            dp[j] = max(dp[j], dp[j-w]*10 + v)
    # print(dp) j range(n+1) range n+1 n 1 if j < w:
            continue
         j < w j w continue if j%w == 0 or dp[j-w]:
            dp[j] = max(dp[j], dp[j-w]*10 + v)
    # print(dp) j%w == 0 or dp[j-w] j%w == 0 j%w j w 0 dp[j-w] dp j-w j w dp[j] = max(dp[j], dp[j-w]*10 + v) dp[j] dp j max(dp[j], dp[j-w]*10 + v) max dp[j] dp j dp[j-w]*10 + v dp[j-w]*10 dp[j-w] dp j-w j w 10 v print(dp[-1]) print dp[-1] dp -1 def inp(): return int(sys.stdin.readline()) def inp(): return int(sys.stdin.readline()) inp b = [0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] b w,v = b[i],i b[i] w a = sorted(inpl(), reverse = True) sorted(inpl(), reverse = True) a v = b[i],i i v def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl(): return list(map(int, sys.stdin.readline().split())) inpl n,m = inpl() inpl() n mod = 10**9+7 10**9+7 mod INF = float('inf') float('inf') INF dp = [0] * (n+1) [0] * (n+1) dp m = inpl() inpl() m
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
a = sorted(inpl(), reverse = True)
b = [0,2,5,5,4,5,6,3,7,6]
dp = [0] * (n+1)

for i in a:
    w,v = b[i],i
    for j in range(n+1):
        if j < w:
            continue
        if j%w == 0 or dp[j-w]:
            dp[j] = max(dp[j], dp[j-w]*10 + v)
    # print(dp)
print(dp[-1])