# 解説放送の１つめ
N,M = map(int, input().split())
A = list(map(int, input().split()))
f = [-1, 2,5,5,4,5,6,3,7,6] # 1-indexed

# dp[i]: マッチi本数で作れる最大の数(str)
dp = [None]*(N+1)
dp[0] = ""

# strの数の大きいほう
def max_str(s1:str, s2:str)->str:
    """return bigger one"""
    l1, l2 = len(s1), len(s2)
    if l1 != l2:
        return s1 if l1>l2 else s2
    if l1 == l2: 
        return s1 if s1>s2 else s2
    
for i in range(2, N+1):
    nxt = ""
    for aj in A:
        # 配列外参照と，i本ちょうどで作れないものはだめ
        if i-f[aj]<0 or dp[i-f[aj]]==None: continue
        nxt = max_str(nxt, 
                      dp[i-f[aj]]+str(aj))
    if nxt!="":
        dp[i] = nxt
    #print(dp)
print(dp[N]) 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 f = [-1, 2,5,5,4,5,6,3,7,6] f [-1, 2,5,5,4,5,6,3,7,6] -1 2 5 5 4 5 6 3 7 6 dp = [None]*(N+1) dp [None]*(N+1) [None] None N+1 N 1 dp[0] = "" dp[0] dp 0 "" def max_str(s1:str, s2:str)->str:
    """return bigger one"""
    l1, l2 = len(s1), len(s2)
    if l1 != l2:
        return s1 if l1>l2 else s2
    if l1 == l2: 
        return s1 if s1>s2 else s2
     max_str """return bigger one""" l1, l2 = len(s1), len(s2) l1 len(s1) len s1 l2 len(s2) len s2 if l1 != l2:
        return s1 if l1>l2 else s2
     l1 != l2 l1 l2 return s1 if l1>l2 else s2 s1 if l1>l2 else s2 l1>l2 l1 l2 s1 s2 if l1 == l2: 
        return s1 if s1>s2 else s2
     l1 == l2 l1 l2 return s1 if s1>s2 else s2 s1 if s1>s2 else s2 s1>s2 s1 s2 s1 s2 s1:str s1 s2:str s2 for i in range(2, N+1):
    nxt = ""
    for aj in A:
        # 配列外参照と，i本ちょうどで作れないものはだめ
        if i-f[aj]<0 or dp[i-f[aj]]==None: continue
        nxt = max_str(nxt, 
                      dp[i-f[aj]]+str(aj))
    if nxt!="":
        dp[i] = nxt
    #print(dp) i range(2, N+1) range 2 N+1 N 1 nxt = "" nxt "" for aj in A:
        # 配列外参照と，i本ちょうどで作れないものはだめ
        if i-f[aj]<0 or dp[i-f[aj]]==None: continue
        nxt = max_str(nxt, 
                      dp[i-f[aj]]+str(aj))
     aj A if i-f[aj]<0 or dp[i-f[aj]]==None: continue
         i-f[aj]<0 or dp[i-f[aj]]==None i-f[aj]<0 i-f[aj] i f[aj] f aj 0 dp[i-f[aj]]==None dp[i-f[aj]] dp i-f[aj] i f[aj] f aj None nxt = max_str(nxt, 
                      dp[i-f[aj]]+str(aj)) nxt max_str(nxt, 
                      dp[i-f[aj]]+str(aj)) max_str nxt dp[i-f[aj]]+str(aj) dp[i-f[aj]] dp i-f[aj] i f[aj] f aj str(aj) str aj if nxt!="":
        dp[i] = nxt
    #print(dp) nxt!="" nxt "" dp[i] = nxt dp[i] dp i nxt print(dp[N]) print dp[N] dp N f = [-1, 2,5,5,4,5,6,3,7,6] [-1, 2,5,5,4,5,6,3,7,6] f M = map(int, input().split()) map(int, input().split()) M nxt = "" "" nxt def max_str(s1:str, s2:str)->str:
    """return bigger one"""
    l1, l2 = len(s1), len(s2)
    if l1 != l2:
        return s1 if l1>l2 else s2
    if l1 == l2: 
        return s1 if s1>s2 else s2
     def max_str(s1:str, s2:str)->str:
    """return bigger one"""
    l1, l2 = len(s1), len(s2)
    if l1 != l2:
        return s1 if l1>l2 else s2
    if l1 == l2: 
        return s1 if s1>s2 else s2
     max_str dp = [None]*(N+1) [None]*(N+1) dp N,M = map(int, input().split()) map(int, input().split()) N A = list(map(int, input().split())) list(map(int, input().split())) A nxt = max_str(nxt, 
                      dp[i-f[aj]]+str(aj)) max_str(nxt, 
                      dp[i-f[aj]]+str(aj)) nxt
# 解説放送の１つめ
N,M = map(int, input().split())
A = list(map(int, input().split()))
f = [-1, 2,5,5,4,5,6,3,7,6] # 1-indexed

# dp[i]: マッチi本数で作れる最大の数(str)
dp = [None]*(N+1)
dp[0] = ""

# strの数の大きいほう
def max_str(s1:str, s2:str)->str:
    """return bigger one"""
    l1, l2 = len(s1), len(s2)
    if l1 != l2:
        return s1 if l1>l2 else s2
    if l1 == l2: 
        return s1 if s1>s2 else s2
    
for i in range(2, N+1):
    nxt = ""
    for aj in A:
        # 配列外参照と，i本ちょうどで作れないものはだめ
        if i-f[aj]<0 or dp[i-f[aj]]==None: continue
        nxt = max_str(nxt, 
                      dp[i-f[aj]]+str(aj))
    if nxt!="":
        dp[i] = nxt
    #print(dp)
print(dp[N])
