from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate
import sys



def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n, m = LI()
values = sorted(LI(), reverse=True)
weights = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]


dp = [-float('inf')] * (n+1)
dp[0] = 0



for i in values:
    for j in range(weights[i], n+1):
        dp[j] = max(dp[j - weights[i]] * 10 + i, dp[j])


print(dp[-1]) from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math math import bisect bisect import random random from itertools import permutations, accumulate import sys sys def LI(): return list(map(int, sys.stdin.readline().split())) LI def I(): return int(sys.stdin.readline()) I def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split())) LIM def LS(): return sys.stdin.readline().split() LS def S(): return sys.stdin.readline() S I() for i in range(n) for i in range(n) i range(n) range n for i in range(n) I() I def IR(n): return [I() for i in range(n)] IR n n LI() for i in range(n) for i in range(n) i range(n) range n for i in range(n) LI() LI def LIR(n): return [LI() for i in range(n)] LIR n n LIM() for i in range(n) for i in range(n) i range(n) range n for i in range(n) LIM() LIM def LIRM(n): return [LIM() for i in range(n)] LIRM n n S() for i in range(n) for i in range(n) i range(n) range n for i in range(n) S() S def SR(n): return [S() for i in range(n)] SR n n LS() for i in range(n) for i in range(n) i range(n) range n for i in range(n) LS() LS def LSR(n): return [LS() for i in range(n)] LSR n n list(S()) for i in range(n) for i in range(n) i range(n) range n for i in range(n) list(S()) list S() S def SRL(n): return [list(S()) for i in range(n)] SRL n n mod = 1000000007 mod 1000000007 n, m = LI() n LI() LI m values = sorted(LI(), reverse=True) values sorted(LI(), reverse=True) sorted LI() LI reverse=True reverse True weights = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] weights [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] 0 2 5 5 4 5 6 3 7 6 dp = [-float('inf')] * (n+1) dp [-float('inf')] * (n+1) [-float('inf')] -float('inf') float('inf') float 'inf' n+1 n 1 dp[0] = 0 dp[0] dp 0 0 for i in values:
    for j in range(weights[i], n+1):
        dp[j] = max(dp[j - weights[i]] * 10 + i, dp[j]) i values for j in range(weights[i], n+1):
        dp[j] = max(dp[j - weights[i]] * 10 + i, dp[j]) j range(weights[i], n+1) range weights[i] weights i n+1 n 1 dp[j] = max(dp[j - weights[i]] * 10 + i, dp[j]) dp[j] dp j max(dp[j - weights[i]] * 10 + i, dp[j]) max dp[j - weights[i]] * 10 + i dp[j - weights[i]] * 10 dp[j - weights[i]] dp j - weights[i] j weights[i] weights i 10 i dp[j] dp j print(dp[-1]) print dp[-1] dp -1 def IR(n): return [I() for i in range(n)] def IR(n): return [I() for i in range(n)] IR def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split())) def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split())) LIM def LIRM(n): return [LIM() for i in range(n)] def LIRM(n): return [LIM() for i in range(n)] LIRM weights = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] weights def LSR(n): return [LS() for i in range(n)] def LSR(n): return [LS() for i in range(n)] LSR def LS(): return sys.stdin.readline().split() def LS(): return sys.stdin.readline().split() LS def SRL(n): return [list(S()) for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] SRL m = LI() LI() m def LI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) LI n, m = LI() LI() n def S(): return sys.stdin.readline() def S(): return sys.stdin.readline() S def LIR(n): return [LI() for i in range(n)] def LIR(n): return [LI() for i in range(n)] LIR def SR(n): return [S() for i in range(n)] def SR(n): return [S() for i in range(n)] SR mod = 1000000007 1000000007 mod values = sorted(LI(), reverse=True) sorted(LI(), reverse=True) values dp = [-float('inf')] * (n+1) [-float('inf')] * (n+1) dp def I(): return int(sys.stdin.readline()) def I(): return int(sys.stdin.readline()) I
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate
import sys



def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n, m = LI()
values = sorted(LI(), reverse=True)
weights = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]


dp = [-float('inf')] * (n+1)
dp[0] = 0



for i in values:
    for j in range(weights[i], n+1):
        dp[j] = max(dp[j - weights[i]] * 10 + i, dp[j])


print(dp[-1])