#import decimal
#decimal.getcontext().prec==500 Floatの桁数を500まで増やす
#Decimal(c).sqrt() それで平方根を求める
#Decimal(1) / Decimal(7) 1/7

from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd
import sys
#input = sys.stdin.readline

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

data=[]
for i,a in enumerate([2,5,5,4,5,6,3,7,6]):
    if i+1 in A:
        data.append([a,i+1])

dic={}
for a,i in reversed(data):
    dic[i]=0
dp=[copy.copy(dic) for i in range(N+1)]

def main(dic1,dic2):
    dic1=sorted([[str(i),dic1[i]] for i in dic],key=lambda x:x[0],reverse=True)
    dic2=sorted([[str(i),dic2[i]] for i in dic],key=lambda x:x[0],reverse=True)
    for a,b in zip(dic1,dic2):
        if a[1]>b[1]:
            return(0)
        if a[1]<b[1]:
            return(1)
    return(0)

def _sum(dic):
    count=0
    for i in dic:
        count+=dic[i]
    return(count)


for a,n in data:
    tempdic=copy.copy(dic)
    tempdic[n]+=1
    if len(dp)-1>=a:
        flag=main(dp[a],tempdic)
        if flag:
            dp[a]=tempdic
    for i in range(len(dp)):
        if i>=a and _sum(dp[i-a]):
            if _sum(dp[i])<_sum(dp[i-a])+1:

                tempdic=copy.copy(dp[i-a])
                tempdic[n]+=1
                dp[i]=tempdic
            elif _sum(dp[i])==_sum(dp[i-a])+1:
                dp[i-a][n]+=1
                flag=main(dp[i],dp[i-a])
                dp[i-a][n]-=1
                if flag:
                    tempdic=copy.copy(dp[i-a])
                    tempdic[n]+=1
                    dp[i]=tempdic
dic=dp[N]
a=""
dic=sorted([[str(i),dic[i]] for i in dic],key=lambda x:x[0],reverse=True)
for i,z in dic:
    for m in range(z):
        a+=i
print(a) from collections import * from itertools import * from bisect import * from heapq import * import copy copy import math math from fractions import gcd import sys sys 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 data=[] data [] for i,a in enumerate([2,5,5,4,5,6,3,7,6]):
    if i+1 in A:
        data.append([a,i+1]) i a enumerate([2,5,5,4,5,6,3,7,6]) enumerate [2,5,5,4,5,6,3,7,6] 2 5 5 4 5 6 3 7 6 if i+1 in A:
        data.append([a,i+1]) i+1 in A i+1 i 1 A data.append([a,i+1]) data.append data append [a,i+1] a i+1 i 1 dic={} dic {} for a,i in reversed(data):
    dic[i]=0 a i reversed(data) reversed data dic[i]=0 dic[i] dic i 0 copy.copy(dic) for i in range(N+1) for i in range(N+1) i range(N+1) range N+1 N 1 for i in range(N+1) copy.copy(dic) copy.copy copy copy dic dp=[copy.copy(dic) for i in range(N+1)] dp [copy.copy(dic) for i in range(N+1)] def main(dic1,dic2):
    dic1=sorted([[str(i),dic1[i]] for i in dic],key=lambda x:x[0],reverse=True)
    dic2=sorted([[str(i),dic2[i]] for i in dic],key=lambda x:x[0],reverse=True)
    for a,b in zip(dic1,dic2):
        if a[1]>b[1]:
            return(0)
        if a[1]<b[1]:
            return(1)
    return(0) main [str(i),dic1[i]] for i in dic for i in dic i dic for i in dic [str(i),dic1[i]] str(i) str i dic1[i] dic1 i dic1=sorted([[str(i),dic1[i]] for i in dic],key=lambda x:x[0],reverse=True) dic1 sorted([[str(i),dic1[i]] for i in dic],key=lambda x:x[0],reverse=True) sorted [[str(i),dic1[i]] for i in dic] key=lambda x:x[0] key lambda x:x[0] x[0] x 0 x reverse=True reverse True [str(i),dic2[i]] for i in dic for i in dic i dic for i in dic [str(i),dic2[i]] str(i) str i dic2[i] dic2 i dic2=sorted([[str(i),dic2[i]] for i in dic],key=lambda x:x[0],reverse=True) dic2 sorted([[str(i),dic2[i]] for i in dic],key=lambda x:x[0],reverse=True) sorted [[str(i),dic2[i]] for i in dic] key=lambda x:x[0] key lambda x:x[0] x[0] x 0 x reverse=True reverse True for a,b in zip(dic1,dic2):
        if a[1]>b[1]:
            return(0)
        if a[1]<b[1]:
            return(1)
     a b zip(dic1,dic2) zip dic1 dic2 if a[1]>b[1]:
            return(0)
         a[1]>b[1] a[1] a 1 b[1] b 1 return(0) 0 if a[1]<b[1]:
            return(1)
     a[1]<b[1] a[1] a 1 b[1] b 1 return(1) 1 return(0) 0 dic1 dic1 dic2 dic2 def _sum(dic):
    count=0
    for i in dic:
        count+=dic[i]
    return(count) _sum count=0 count 0 for i in dic:
        count+=dic[i]
     i dic count+=dic[i] count dic[i] dic i return(count) count dic dic for a,n in data:
    tempdic=copy.copy(dic)
    tempdic[n]+=1
    if len(dp)-1>=a:
        flag=main(dp[a],tempdic)
        if flag:
            dp[a]=tempdic
    for i in range(len(dp)):
        if i>=a and _sum(dp[i-a]):
            if _sum(dp[i])<_sum(dp[i-a])+1:

                tempdic=copy.copy(dp[i-a])
                tempdic[n]+=1
                dp[i]=tempdic
            elif _sum(dp[i])==_sum(dp[i-a])+1:
                dp[i-a][n]+=1
                flag=main(dp[i],dp[i-a])
                dp[i-a][n]-=1
                if flag:
                    tempdic=copy.copy(dp[i-a])
                    tempdic[n]+=1
                    dp[i]=tempdic a n data tempdic=copy.copy(dic) tempdic copy.copy(dic) copy.copy copy copy dic tempdic[n]+=1 tempdic[n] tempdic n 1 if len(dp)-1>=a:
        flag=main(dp[a],tempdic)
        if flag:
            dp[a]=tempdic
     len(dp)-1>=a len(dp)-1 len(dp) len dp 1 a flag=main(dp[a],tempdic) flag main(dp[a],tempdic) main dp[a] dp a tempdic if flag:
            dp[a]=tempdic
     flag dp[a]=tempdic dp[a] dp a tempdic for i in range(len(dp)):
        if i>=a and _sum(dp[i-a]):
            if _sum(dp[i])<_sum(dp[i-a])+1:

                tempdic=copy.copy(dp[i-a])
                tempdic[n]+=1
                dp[i]=tempdic
            elif _sum(dp[i])==_sum(dp[i-a])+1:
                dp[i-a][n]+=1
                flag=main(dp[i],dp[i-a])
                dp[i-a][n]-=1
                if flag:
                    tempdic=copy.copy(dp[i-a])
                    tempdic[n]+=1
                    dp[i]=tempdic i range(len(dp)) range len(dp) len dp if i>=a and _sum(dp[i-a]):
            if _sum(dp[i])<_sum(dp[i-a])+1:

                tempdic=copy.copy(dp[i-a])
                tempdic[n]+=1
                dp[i]=tempdic
            elif _sum(dp[i])==_sum(dp[i-a])+1:
                dp[i-a][n]+=1
                flag=main(dp[i],dp[i-a])
                dp[i-a][n]-=1
                if flag:
                    tempdic=copy.copy(dp[i-a])
                    tempdic[n]+=1
                    dp[i]=tempdic i>=a and _sum(dp[i-a]) i>=a i a _sum(dp[i-a]) _sum dp[i-a] dp i-a i a if _sum(dp[i])<_sum(dp[i-a])+1:

                tempdic=copy.copy(dp[i-a])
                tempdic[n]+=1
                dp[i]=tempdic
            elif _sum(dp[i])==_sum(dp[i-a])+1:
                dp[i-a][n]+=1
                flag=main(dp[i],dp[i-a])
                dp[i-a][n]-=1
                if flag:
                    tempdic=copy.copy(dp[i-a])
                    tempdic[n]+=1
                    dp[i]=tempdic _sum(dp[i])<_sum(dp[i-a])+1 _sum(dp[i]) _sum dp[i] dp i _sum(dp[i-a])+1 _sum(dp[i-a]) _sum dp[i-a] dp i-a i a 1 tempdic=copy.copy(dp[i-a]) tempdic copy.copy(dp[i-a]) copy.copy copy copy dp[i-a] dp i-a i a tempdic[n]+=1 tempdic[n] tempdic n 1 dp[i]=tempdic dp[i] dp i tempdic elif _sum(dp[i])==_sum(dp[i-a])+1:
                dp[i-a][n]+=1
                flag=main(dp[i],dp[i-a])
                dp[i-a][n]-=1
                if flag:
                    tempdic=copy.copy(dp[i-a])
                    tempdic[n]+=1
                    dp[i]=tempdic _sum(dp[i])==_sum(dp[i-a])+1 _sum(dp[i]) _sum dp[i] dp i _sum(dp[i-a])+1 _sum(dp[i-a]) _sum dp[i-a] dp i-a i a 1 dp[i-a][n]+=1 dp[i-a][n] [i-a] dp i-a i a n 1 flag=main(dp[i],dp[i-a]) flag main(dp[i],dp[i-a]) main dp[i] dp i dp[i-a] dp i-a i a dp[i-a][n]-=1 dp[i-a][n] [i-a] dp i-a i a n 1 if flag:
                    tempdic=copy.copy(dp[i-a])
                    tempdic[n]+=1
                    dp[i]=tempdic flag tempdic=copy.copy(dp[i-a]) tempdic copy.copy(dp[i-a]) copy.copy copy copy dp[i-a] dp i-a i a tempdic[n]+=1 tempdic[n] tempdic n 1 dp[i]=tempdic dp[i] dp i tempdic dic=dp[N] dic dp[N] dp N a="" a "" [str(i),dic[i]] for i in dic for i in dic i dic for i in dic [str(i),dic[i]] str(i) str i dic[i] dic i dic=sorted([[str(i),dic[i]] for i in dic],key=lambda x:x[0],reverse=True) dic sorted([[str(i),dic[i]] for i in dic],key=lambda x:x[0],reverse=True) sorted [[str(i),dic[i]] for i in dic] key=lambda x:x[0] key lambda x:x[0] x[0] x 0 x reverse=True reverse True for i,z in dic:
    for m in range(z):
        a+=i i z dic for m in range(z):
        a+=i m range(z) range z a+=i a i print(a) print a dic=dp[N] dp[N] dic N,M=map(int,input().split()) map(int,input().split()) N tempdic=copy.copy(dic) copy.copy(dic) tempdic data=[] [] data a="" "" a a+=i i a def main(dic1,dic2):
    dic1=sorted([[str(i),dic1[i]] for i in dic],key=lambda x:x[0],reverse=True)
    dic2=sorted([[str(i),dic2[i]] for i in dic],key=lambda x:x[0],reverse=True)
    for a,b in zip(dic1,dic2):
        if a[1]>b[1]:
            return(0)
        if a[1]<b[1]:
            return(1)
    return(0) def main(dic1,dic2):
    dic1=sorted([[str(i),dic1[i]] for i in dic],key=lambda x:x[0],reverse=True)
    dic2=sorted([[str(i),dic2[i]] for i in dic],key=lambda x:x[0],reverse=True)
    for a,b in zip(dic1,dic2):
        if a[1]>b[1]:
            return(0)
        if a[1]<b[1]:
            return(1)
    return(0) main dic=sorted([[str(i),dic[i]] for i in dic],key=lambda x:x[0],reverse=True) sorted([[str(i),dic[i]] for i in dic],key=lambda x:x[0],reverse=True) dic dp=[copy.copy(dic) for i in range(N+1)] [copy.copy(dic) for i in range(N+1)] dp tempdic=copy.copy(dp[i-a]) copy.copy(dp[i-a]) tempdic flag=main(dp[i],dp[i-a]) main(dp[i],dp[i-a]) flag dic={} {} dic flag=main(dp[a],tempdic) main(dp[a],tempdic) flag A=list(map(int,input().split())) list(map(int,input().split())) A def _sum(dic):
    count=0
    for i in dic:
        count+=dic[i]
    return(count) def _sum(dic):
    count=0
    for i in dic:
        count+=dic[i]
    return(count) _sum tempdic=copy.copy(dp[i-a]) copy.copy(dp[i-a]) tempdic M=map(int,input().split()) map(int,input().split()) M
#import decimal
#decimal.getcontext().prec==500 Floatの桁数を500まで増やす
#Decimal(c).sqrt() それで平方根を求める
#Decimal(1) / Decimal(7) 1/7

from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd
import sys
#input = sys.stdin.readline

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

data=[]
for i,a in enumerate([2,5,5,4,5,6,3,7,6]):
    if i+1 in A:
        data.append([a,i+1])

dic={}
for a,i in reversed(data):
    dic[i]=0
dp=[copy.copy(dic) for i in range(N+1)]

def main(dic1,dic2):
    dic1=sorted([[str(i),dic1[i]] for i in dic],key=lambda x:x[0],reverse=True)
    dic2=sorted([[str(i),dic2[i]] for i in dic],key=lambda x:x[0],reverse=True)
    for a,b in zip(dic1,dic2):
        if a[1]>b[1]:
            return(0)
        if a[1]<b[1]:
            return(1)
    return(0)

def _sum(dic):
    count=0
    for i in dic:
        count+=dic[i]
    return(count)


for a,n in data:
    tempdic=copy.copy(dic)
    tempdic[n]+=1
    if len(dp)-1>=a:
        flag=main(dp[a],tempdic)
        if flag:
            dp[a]=tempdic
    for i in range(len(dp)):
        if i>=a and _sum(dp[i-a]):
            if _sum(dp[i])<_sum(dp[i-a])+1:

                tempdic=copy.copy(dp[i-a])
                tempdic[n]+=1
                dp[i]=tempdic
            elif _sum(dp[i])==_sum(dp[i-a])+1:
                dp[i-a][n]+=1
                flag=main(dp[i],dp[i-a])
                dp[i-a][n]-=1
                if flag:
                    tempdic=copy.copy(dp[i-a])
                    tempdic[n]+=1
                    dp[i]=tempdic
dic=dp[N]
a=""
dic=sorted([[str(i),dic[i]] for i in dic],key=lambda x:x[0],reverse=True)
for i,z in dic:
    for m in range(z):
        a+=i
print(a)
