N,M=map(int,input().split())
A=list(map(int,input().split()))
d={2:0,3:0,4:0,5:0,6:0,7:0}
for i in A:
    if i==1:
        d[2]=1
    elif i==7:
        d[3]=7
    elif i==8:
        d[7]=8
    elif i==4:
        d[4]=4
    elif i==6 or i==9:
        if d[6]<i:
            d[6]=i
    else:
        if d[5]<i:
            d[5]=i
l=[]
for i in d.keys():
    if d[i]:
        l.append(i)
l.sort()
a=[]
m=0
if len(l)>=4:
    for i in range(4):
        for j in range(4):
            for k in range(4):
                t=N-i*l[1]-j*l[2]-k*l[3]
                if t%l[0] or t<0:
                    continue
                ke=i+j+k+t//l[0]
                if ke<m:
                    continue
                else:
                    s=[d[l[1]]]*i+[d[l[2]]]*j+[d[l[3]]]*k+[d[l[0]]]*(t//l[0])
                    s.sort(reverse=1)
                    if ke==m:
                        a.append(s)
                    else:
                        a=[s]
                        m=ke
    print(*max(a),sep="")
elif len(l)==3:
    for i in range(5):
        for j in range(5):
            t=(N-i*l[1]-j*l[2])
            if t%l[0] or t<0:
                continue
            ke=i+j+t//l[0]
            if ke<m:
                continue
            else:
                s=[d[l[1]]]*i+[d[l[2]]]*j+[d[l[0]]]*(t//l[0])
                s.sort(reverse=1)
                if ke==m:
                    a.append(s)
                else:
                    a=[s]
                    m=ke
    print(*max(a),sep="")
elif len(l)==2:
    for i in range(6):
        if (N-l[1]*i)%l[0]==0:
            a=[d[l[1]]]*i+[d[l[0]]]*((N-i*l[1])//l[0])
            a.sort(reverse=1)
            print(*a,sep="")
            break
else:
    a=[d[l[0]]]*(N//l[0])
    print(*a,sep="") 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 d={2:0,3:0,4:0,5:0,6:0,7:0} d {2:0,3:0,4:0,5:0,6:0,7:0} 2 2 0 3 3 0 4 4 0 5 5 0 6 6 0 7 7 0 for i in A:
    if i==1:
        d[2]=1
    elif i==7:
        d[3]=7
    elif i==8:
        d[7]=8
    elif i==4:
        d[4]=4
    elif i==6 or i==9:
        if d[6]<i:
            d[6]=i
    else:
        if d[5]<i:
            d[5]=i i A if i==1:
        d[2]=1
    elif i==7:
        d[3]=7
    elif i==8:
        d[7]=8
    elif i==4:
        d[4]=4
    elif i==6 or i==9:
        if d[6]<i:
            d[6]=i
    else:
        if d[5]<i:
            d[5]=i i==1 i 1 d[2]=1 d[2] d 2 1 elif i==7:
        d[3]=7
     i==7 i 7 d[3]=7 d[3] d 3 7 elif i==8:
        d[7]=8
     i==8 i 8 d[7]=8 d[7] d 7 8 elif i==4:
        d[4]=4
     i==4 i 4 d[4]=4 d[4] d 4 4 elif i==6 or i==9:
        if d[6]<i:
            d[6]=i
     i==6 or i==9 i==6 i 6 i==9 i 9 if d[6]<i:
            d[6]=i
     d[6]<i d[6] d 6 i d[6]=i d[6] d 6 i if d[5]<i:
            d[5]=i d[5]<i d[5] d 5 i d[5]=i d[5] d 5 i l=[] l [] for i in d.keys():
    if d[i]:
        l.append(i) i d.keys() d.keys d keys if d[i]:
        l.append(i) d[i] d i l.append(i) l.append l append i l.sort() l.sort l sort a=[] a [] m=0 m 0 if len(l)>=4:
    for i in range(4):
        for j in range(4):
            for k in range(4):
                t=N-i*l[1]-j*l[2]-k*l[3]
                if t%l[0] or t<0:
                    continue
                ke=i+j+k+t//l[0]
                if ke<m:
                    continue
                else:
                    s=[d[l[1]]]*i+[d[l[2]]]*j+[d[l[3]]]*k+[d[l[0]]]*(t//l[0])
                    s.sort(reverse=1)
                    if ke==m:
                        a.append(s)
                    else:
                        a=[s]
                        m=ke
    print(*max(a),sep="")
elif len(l)==3:
    for i in range(5):
        for j in range(5):
            t=(N-i*l[1]-j*l[2])
            if t%l[0] or t<0:
                continue
            ke=i+j+t//l[0]
            if ke<m:
                continue
            else:
                s=[d[l[1]]]*i+[d[l[2]]]*j+[d[l[0]]]*(t//l[0])
                s.sort(reverse=1)
                if ke==m:
                    a.append(s)
                else:
                    a=[s]
                    m=ke
    print(*max(a),sep="")
elif len(l)==2:
    for i in range(6):
        if (N-l[1]*i)%l[0]==0:
            a=[d[l[1]]]*i+[d[l[0]]]*((N-i*l[1])//l[0])
            a.sort(reverse=1)
            print(*a,sep="")
            break
else:
    a=[d[l[0]]]*(N//l[0])
    print(*a,sep="") len(l)>=4 len(l) len l 4 for i in range(4):
        for j in range(4):
            for k in range(4):
                t=N-i*l[1]-j*l[2]-k*l[3]
                if t%l[0] or t<0:
                    continue
                ke=i+j+k+t//l[0]
                if ke<m:
                    continue
                else:
                    s=[d[l[1]]]*i+[d[l[2]]]*j+[d[l[3]]]*k+[d[l[0]]]*(t//l[0])
                    s.sort(reverse=1)
                    if ke==m:
                        a.append(s)
                    else:
                        a=[s]
                        m=ke
     i range(4) range 4 for j in range(4):
            for k in range(4):
                t=N-i*l[1]-j*l[2]-k*l[3]
                if t%l[0] or t<0:
                    continue
                ke=i+j+k+t//l[0]
                if ke<m:
                    continue
                else:
                    s=[d[l[1]]]*i+[d[l[2]]]*j+[d[l[3]]]*k+[d[l[0]]]*(t//l[0])
                    s.sort(reverse=1)
                    if ke==m:
                        a.append(s)
                    else:
                        a=[s]
                        m=ke
     j range(4) range 4 for k in range(4):
                t=N-i*l[1]-j*l[2]-k*l[3]
                if t%l[0] or t<0:
                    continue
                ke=i+j+k+t//l[0]
                if ke<m:
                    continue
                else:
                    s=[d[l[1]]]*i+[d[l[2]]]*j+[d[l[3]]]*k+[d[l[0]]]*(t//l[0])
                    s.sort(reverse=1)
                    if ke==m:
                        a.append(s)
                    else:
                        a=[s]
                        m=ke
     k range(4) range 4 t=N-i*l[1]-j*l[2]-k*l[3] t N-i*l[1]-j*l[2]-k*l[3] N-i*l[1]-j*l[2] N-i*l[1] N i*l[1] i l[1] l 1 j*l[2] j l[2] l 2 k*l[3] k l[3] l 3 if t%l[0] or t<0:
                    continue
                 t%l[0] or t<0 t%l[0] t l[0] l 0 t<0 t 0 continue ke=i+j+k+t//l[0] ke i+j+k+t//l[0] i+j+k i+j i j k t//l[0] t l[0] l 0 if ke<m:
                    continue
                else:
                    s=[d[l[1]]]*i+[d[l[2]]]*j+[d[l[3]]]*k+[d[l[0]]]*(t//l[0])
                    s.sort(reverse=1)
                    if ke==m:
                        a.append(s)
                    else:
                        a=[s]
                        m=ke
     ke<m ke m continue s=[d[l[1]]]*i+[d[l[2]]]*j+[d[l[3]]]*k+[d[l[0]]]*(t//l[0]) s [d[l[1]]]*i+[d[l[2]]]*j+[d[l[3]]]*k+[d[l[0]]]*(t//l[0]) [d[l[1]]]*i+[d[l[2]]]*j+[d[l[3]]]*k [d[l[1]]]*i+[d[l[2]]]*j [d[l[1]]]*i [d[l[1]]] d[l[1]] d l[1] l 1 i [d[l[2]]]*j [d[l[2]]] d[l[2]] d l[2] l 2 j [d[l[3]]]*k [d[l[3]]] d[l[3]] d l[3] l 3 k [d[l[0]]]*(t//l[0]) [d[l[0]]] d[l[0]] d l[0] l 0 t//l[0] t l[0] l 0 s.sort(reverse=1) s.sort s sort reverse=1 reverse 1 if ke==m:
                        a.append(s)
                    else:
                        a=[s]
                        m=ke
     ke==m ke m a.append(s) a.append a append s a=[s] a [s] s m=ke m ke print(*max(a),sep="") print *max(a) max(a) max a sep="" sep "" elif len(l)==3:
    for i in range(5):
        for j in range(5):
            t=(N-i*l[1]-j*l[2])
            if t%l[0] or t<0:
                continue
            ke=i+j+t//l[0]
            if ke<m:
                continue
            else:
                s=[d[l[1]]]*i+[d[l[2]]]*j+[d[l[0]]]*(t//l[0])
                s.sort(reverse=1)
                if ke==m:
                    a.append(s)
                else:
                    a=[s]
                    m=ke
    print(*max(a),sep="") len(l)==3 len(l) len l 3 for i in range(5):
        for j in range(5):
            t=(N-i*l[1]-j*l[2])
            if t%l[0] or t<0:
                continue
            ke=i+j+t//l[0]
            if ke<m:
                continue
            else:
                s=[d[l[1]]]*i+[d[l[2]]]*j+[d[l[0]]]*(t//l[0])
                s.sort(reverse=1)
                if ke==m:
                    a.append(s)
                else:
                    a=[s]
                    m=ke
     i range(5) range 5 for j in range(5):
            t=(N-i*l[1]-j*l[2])
            if t%l[0] or t<0:
                continue
            ke=i+j+t//l[0]
            if ke<m:
                continue
            else:
                s=[d[l[1]]]*i+[d[l[2]]]*j+[d[l[0]]]*(t//l[0])
                s.sort(reverse=1)
                if ke==m:
                    a.append(s)
                else:
                    a=[s]
                    m=ke
     j range(5) range 5 t=(N-i*l[1]-j*l[2]) t N-i*l[1]-j*l[2] N-i*l[1] N i*l[1] i l[1] l 1 j*l[2] j l[2] l 2 if t%l[0] or t<0:
                continue
             t%l[0] or t<0 t%l[0] t l[0] l 0 t<0 t 0 continue ke=i+j+t//l[0] ke i+j+t//l[0] i+j i j t//l[0] t l[0] l 0 if ke<m:
                continue
            else:
                s=[d[l[1]]]*i+[d[l[2]]]*j+[d[l[0]]]*(t//l[0])
                s.sort(reverse=1)
                if ke==m:
                    a.append(s)
                else:
                    a=[s]
                    m=ke
     ke<m ke m continue s=[d[l[1]]]*i+[d[l[2]]]*j+[d[l[0]]]*(t//l[0]) s [d[l[1]]]*i+[d[l[2]]]*j+[d[l[0]]]*(t//l[0]) [d[l[1]]]*i+[d[l[2]]]*j [d[l[1]]]*i [d[l[1]]] d[l[1]] d l[1] l 1 i [d[l[2]]]*j [d[l[2]]] d[l[2]] d l[2] l 2 j [d[l[0]]]*(t//l[0]) [d[l[0]]] d[l[0]] d l[0] l 0 t//l[0] t l[0] l 0 s.sort(reverse=1) s.sort s sort reverse=1 reverse 1 if ke==m:
                    a.append(s)
                else:
                    a=[s]
                    m=ke
     ke==m ke m a.append(s) a.append a append s a=[s] a [s] s m=ke m ke print(*max(a),sep="") print *max(a) max(a) max a sep="" sep "" elif len(l)==2:
    for i in range(6):
        if (N-l[1]*i)%l[0]==0:
            a=[d[l[1]]]*i+[d[l[0]]]*((N-i*l[1])//l[0])
            a.sort(reverse=1)
            print(*a,sep="")
            break len(l)==2 len(l) len l 2 for i in range(6):
        if (N-l[1]*i)%l[0]==0:
            a=[d[l[1]]]*i+[d[l[0]]]*((N-i*l[1])//l[0])
            a.sort(reverse=1)
            print(*a,sep="")
            break i range(6) range 6 if (N-l[1]*i)%l[0]==0:
            a=[d[l[1]]]*i+[d[l[0]]]*((N-i*l[1])//l[0])
            a.sort(reverse=1)
            print(*a,sep="")
            break (N-l[1]*i)%l[0]==0 (N-l[1]*i)%l[0] N-l[1]*i N l[1]*i l[1] l 1 i l[0] l 0 0 a=[d[l[1]]]*i+[d[l[0]]]*((N-i*l[1])//l[0]) a [d[l[1]]]*i+[d[l[0]]]*((N-i*l[1])//l[0]) [d[l[1]]]*i [d[l[1]]] d[l[1]] d l[1] l 1 i [d[l[0]]]*((N-i*l[1])//l[0]) [d[l[0]]] d[l[0]] d l[0] l 0 (N-i*l[1])//l[0] N-i*l[1] N i*l[1] i l[1] l 1 l[0] l 0 a.sort(reverse=1) a.sort a sort reverse=1 reverse 1 print(*a,sep="") print *a a sep="" sep "" break a=[d[l[0]]]*(N//l[0]) a [d[l[0]]]*(N//l[0]) [d[l[0]]] d[l[0]] d l[0] l 0 N//l[0] N l[0] l 0 print(*a,sep="") print *a a sep="" sep "" d={2:0,3:0,4:0,5:0,6:0,7:0} {2:0,3:0,4:0,5:0,6:0,7:0} d a=[s] [s] a l=[] [] l a=[d[l[0]]]*(N//l[0]) [d[l[0]]]*(N//l[0]) a t=(N-i*l[1]-j*l[2]) N-i*l[1]-j*l[2] t m=ke ke m M=map(int,input().split()) map(int,input().split()) M s=[d[l[1]]]*i+[d[l[2]]]*j+[d[l[3]]]*k+[d[l[0]]]*(t//l[0]) [d[l[1]]]*i+[d[l[2]]]*j+[d[l[3]]]*k+[d[l[0]]]*(t//l[0]) s a=[s] [s] a ke=i+j+t//l[0] i+j+t//l[0] ke s=[d[l[1]]]*i+[d[l[2]]]*j+[d[l[0]]]*(t//l[0]) [d[l[1]]]*i+[d[l[2]]]*j+[d[l[0]]]*(t//l[0]) s A=list(map(int,input().split())) list(map(int,input().split())) A ke=i+j+k+t//l[0] i+j+k+t//l[0] ke m=ke ke m a=[] [] a t=N-i*l[1]-j*l[2]-k*l[3] N-i*l[1]-j*l[2]-k*l[3] t a=[d[l[1]]]*i+[d[l[0]]]*((N-i*l[1])//l[0]) [d[l[1]]]*i+[d[l[0]]]*((N-i*l[1])//l[0]) a N,M=map(int,input().split()) map(int,input().split()) N m=0 0 m
N,M=map(int,input().split())
A=list(map(int,input().split()))
d={2:0,3:0,4:0,5:0,6:0,7:0}
for i in A:
    if i==1:
        d[2]=1
    elif i==7:
        d[3]=7
    elif i==8:
        d[7]=8
    elif i==4:
        d[4]=4
    elif i==6 or i==9:
        if d[6]<i:
            d[6]=i
    else:
        if d[5]<i:
            d[5]=i
l=[]
for i in d.keys():
    if d[i]:
        l.append(i)
l.sort()
a=[]
m=0
if len(l)>=4:
    for i in range(4):
        for j in range(4):
            for k in range(4):
                t=N-i*l[1]-j*l[2]-k*l[3]
                if t%l[0] or t<0:
                    continue
                ke=i+j+k+t//l[0]
                if ke<m:
                    continue
                else:
                    s=[d[l[1]]]*i+[d[l[2]]]*j+[d[l[3]]]*k+[d[l[0]]]*(t//l[0])
                    s.sort(reverse=1)
                    if ke==m:
                        a.append(s)
                    else:
                        a=[s]
                        m=ke
    print(*max(a),sep="")
elif len(l)==3:
    for i in range(5):
        for j in range(5):
            t=(N-i*l[1]-j*l[2])
            if t%l[0] or t<0:
                continue
            ke=i+j+t//l[0]
            if ke<m:
                continue
            else:
                s=[d[l[1]]]*i+[d[l[2]]]*j+[d[l[0]]]*(t//l[0])
                s.sort(reverse=1)
                if ke==m:
                    a.append(s)
                else:
                    a=[s]
                    m=ke
    print(*max(a),sep="")
elif len(l)==2:
    for i in range(6):
        if (N-l[1]*i)%l[0]==0:
            a=[d[l[1]]]*i+[d[l[0]]]*((N-i*l[1])//l[0])
            a.sort(reverse=1)
            print(*a,sep="")
            break
else:
    a=[d[l[0]]]*(N//l[0])
    print(*a,sep="")