N,M = map(int,input().split())
*A, = map(int,input().split())
B = sorted((([2,5,5,4,5,6,3,7,6][a-1],a) for a in A),key = lambda x:(x[0],-x[1]))
i = 1
while i<len(B):
    if B[i][0]==B[i-1][0]:
        B.pop(i)
    else:
        i+=1
i = [0]*(len(B)-1)
if len(B)==1:
    print(str(B[0][1])*(N//B[0][0]))
    exit()
ans = []
while i[-1]<B[0][0]:
    tmp = N - sum(j*b[0] for j,b in zip(i,B[1:]))
    if tmp>=0 and tmp%B[0][0] == 0:
        num = ""
        for k,n in sorted(zip([b for _,b in B],[tmp//B[0][0]]+i),key = lambda x:-x[0]):
            num += str(k)*n
        ans.append(int(num))
    i[0]+=1
    for j in range(len(i)-1):
        if i[j]==B[0][0]:
            i[j+1]+=1
            i[j]=0
print(max(ans)) N,M = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M *A, = map(int,input().split()) *A A map(int,input().split()) map int input().split() ().split () input split ([2,5,5,4,5,6,3,7,6][a-1],a) for a in A for a in A a A for a in A ([2,5,5,4,5,6,3,7,6][a-1],a) [2,5,5,4,5,6,3,7,6][a-1] [2,5,5,4,5,6,3,7,6] 2 5 5 4 5 6 3 7 6 a-1 a 1 a B = sorted((([2,5,5,4,5,6,3,7,6][a-1],a) for a in A),key = lambda x:(x[0],-x[1])) B sorted((([2,5,5,4,5,6,3,7,6][a-1],a) for a in A),key = lambda x:(x[0],-x[1])) sorted (([2,5,5,4,5,6,3,7,6][a-1],a) for a in A) key = lambda x:(x[0],-x[1]) key lambda x:(x[0],-x[1]) (x[0],-x[1]) x[0] x 0 -x[1] x[1] x 1 x i = 1 i 1 while i<len(B):
    if B[i][0]==B[i-1][0]:
        B.pop(i)
    else:
        i+=1 i<len(B) i len(B) len B if B[i][0]==B[i-1][0]:
        B.pop(i)
    else:
        i+=1 B[i][0]==B[i-1][0] B[i][0] [i] B i 0 B[i-1][0] [i-1] B i-1 i 1 0 B.pop(i) B.pop B pop i i+=1 i 1 i = [0]*(len(B)-1) i [0]*(len(B)-1) [0] 0 len(B)-1 len(B) len B 1 if len(B)==1:
    print(str(B[0][1])*(N//B[0][0]))
    exit() len(B)==1 len(B) len B 1 print(str(B[0][1])*(N//B[0][0])) print str(B[0][1])*(N//B[0][0]) str(B[0][1]) str B[0][1] [0] B 0 1 N//B[0][0] N B[0][0] [0] B 0 0 exit() exit ans = [] ans [] while i[-1]<B[0][0]:
    tmp = N - sum(j*b[0] for j,b in zip(i,B[1:]))
    if tmp>=0 and tmp%B[0][0] == 0:
        num = ""
        for k,n in sorted(zip([b for _,b in B],[tmp//B[0][0]]+i),key = lambda x:-x[0]):
            num += str(k)*n
        ans.append(int(num))
    i[0]+=1
    for j in range(len(i)-1):
        if i[j]==B[0][0]:
            i[j+1]+=1
            i[j]=0 i[-1]<B[0][0] i[-1] i -1 B[0][0] [0] B 0 0 tmp = N - sum(j*b[0] for j,b in zip(i,B[1:])) tmp N - sum(j*b[0] for j,b in zip(i,B[1:])) N sum(j*b[0] for j,b in zip(i,B[1:])) sum j*b[0] j b[0] b 0 if tmp>=0 and tmp%B[0][0] == 0:
        num = ""
        for k,n in sorted(zip([b for _,b in B],[tmp//B[0][0]]+i),key = lambda x:-x[0]):
            num += str(k)*n
        ans.append(int(num))
     tmp>=0 and tmp%B[0][0] == 0 tmp>=0 tmp 0 tmp%B[0][0] == 0 tmp%B[0][0] tmp B[0][0] [0] B 0 0 0 num = "" num "" for k,n in sorted(zip([b for _,b in B],[tmp//B[0][0]]+i),key = lambda x:-x[0]):
            num += str(k)*n
         k n sorted(zip([b for _,b in B],[tmp//B[0][0]]+i),key = lambda x:-x[0]) sorted zip([b for _,b in B],[tmp//B[0][0]]+i) zip [b for _,b in B] [tmp//B[0][0]]+i [tmp//B[0][0]] tmp//B[0][0] tmp B[0][0] [0] B 0 0 i key = lambda x:-x[0] key lambda x:-x[0] -x[0] x[0] x 0 x num += str(k)*n num str(k)*n str(k) str k n ans.append(int(num)) ans.append ans append int(num) int num i[0]+=1 i[0] i 0 1 for j in range(len(i)-1):
        if i[j]==B[0][0]:
            i[j+1]+=1
            i[j]=0 j range(len(i)-1) range len(i)-1 len(i) len i 1 if i[j]==B[0][0]:
            i[j+1]+=1
            i[j]=0 i[j]==B[0][0] i[j] i j B[0][0] [0] B 0 0 i[j+1]+=1 i[j+1] i j+1 j 1 1 i[j]=0 i[j] i j 0 print(max(ans)) print max(ans) max ans M = map(int,input().split()) map(int,input().split()) M i+=1 1 i num += str(k)*n str(k)*n num B = sorted((([2,5,5,4,5,6,3,7,6][a-1],a) for a in A),key = lambda x:(x[0],-x[1])) sorted((([2,5,5,4,5,6,3,7,6][a-1],a) for a in A),key = lambda x:(x[0],-x[1])) B i = 1 1 i i = [0]*(len(B)-1) [0]*(len(B)-1) i ans = [] [] ans tmp = N - sum(j*b[0] for j,b in zip(i,B[1:])) N - sum(j*b[0] for j,b in zip(i,B[1:])) tmp N,M = map(int,input().split()) map(int,input().split()) N num = "" "" num
N,M = map(int,input().split())
*A, = map(int,input().split())
B = sorted((([2,5,5,4,5,6,3,7,6][a-1],a) for a in A),key = lambda x:(x[0],-x[1]))
i = 1
while i<len(B):
    if B[i][0]==B[i-1][0]:
        B.pop(i)
    else:
        i+=1
i = [0]*(len(B)-1)
if len(B)==1:
    print(str(B[0][1])*(N//B[0][0]))
    exit()
ans = []
while i[-1]<B[0][0]:
    tmp = N - sum(j*b[0] for j,b in zip(i,B[1:]))
    if tmp>=0 and tmp%B[0][0] == 0:
        num = ""
        for k,n in sorted(zip([b for _,b in B],[tmp//B[0][0]]+i),key = lambda x:-x[0]):
            num += str(k)*n
        ans.append(int(num))
    i[0]+=1
    for j in range(len(i)-1):
        if i[j]==B[0][0]:
            i[j+1]+=1
            i[j]=0
print(max(ans))