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

if 1 in A:
    if N%2==0:
        print("1"*(N//2))
    else:
        if 7 in A:
            print("7"+"1"*(N//2-1))
        elif 5 in A:
            print("5"+"1"*(N//2-2))
        elif 3 in A:
            print("3"+"1"*(N//2-2))
        elif 2 in A:
            print("2"+"1"*(N//2-2))
        else:
            print("8"+"1"*(N//2-3))
else:
    B=[[] for i in range(0,10)]
    for i in range(0,M):
        if 2 in A:
            B[5].append(2)
        if 3 in A:
            B[5].append(3)
        if 4 in A:
            B[4].append(4)
        if 5 in A:
            B[5].append(5)
        if 6 in A:
            B[6].append(6)
        if 7 in A:
            B[3].append(7)
        if 8 in A:
            B[7].append(8)
        if 9 in A:
            B[6].append(9)


    dp=['n' for i in range(0,max(10,N+1))]
    for i in range(0,min(N+1,10)):
        if i==2:
            if 2 in A:
                dp[5]='2'
        if i==3:
            if 3 in A:
                dp[5]='3'
        if i==4:
            if 4 in A:
                dp[4]='4'
        if i==5:
            if 5 in A:
                dp[5]='5'
        if i==6:
            if 6 in A:
                dp[6]='6'
        if i==7:
            if 7 in A:
                dp[3]='7'
        if i==8:
            if 8 in A:
                dp[7]='8'
        if i==9:
            if 9 in A:
                dp[6]='9'

    if N>=6:
        a='0'
        b='0'
        c='0'
        if B[3]!=[]:
            b='77'
        if dp[6]=='n':
            a=int(a)
            b=int(b)
            c=int(c)
            x=max(a,b,c)
            if x!=0:
                dp[6]=str(x)
        else:
            a=int(a)
            b=int(b)
            c=int(c)
            d=int(dp[6])
            dp[6]=str(max(a,b,c,d))

    if N>=7:
        a='0'
        b='0'
        c='0'
        d='0'
        if B[3]!=[] and dp[4]!='n':
            b='7'+dp[4]
        if B[4]!=[] and dp[3]!='n':
            c='47'
        if dp[7]=='n':
            a=int(a)
            b=int(b)
            c=int(c)
            d=int(d)
            x=max(a,b,c,d)
            if x!=0:
                dp[7]=str(x)
        else:
            a=int(a)
            b=int(b)
            c=int(c)
            d=int(d)
            e=int(dp[7])
            dp[7]=str(max(e,a,b,c,d))

    for i in range(8,N+1):
        a='0'
        b='0'
        c='0'
        d='0'
        e='0'
        f='0'
        if B[3] and dp[i-3]!='n':
            b='7'+dp[i-3]
        if B[4] and dp[i-4]!='n':
            c='4'+dp[i-4]
        if B[5] and dp[i-5]!='n':
            d=str(max(B[5]))+dp[i-5]
        if B[6] and dp[i-6]!='n':
            e=str(max(B[6]))+dp[i-6]
        if B[7] and dp[i-7]!='n':
            f='8'+dp[i-7]
        a=int(a)
        b=int(b)
        c=int(c)
        d=int(d)
        e=int(e)
        f=int(f)
        x=max(a,b,c,d,e,f)
        if x==0:
            dp[i]='n'
        else:
            dp[i]=str(x)
    print(int(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 A.sort() A.sort A sort if 1 in A:
    if N%2==0:
        print("1"*(N//2))
    else:
        if 7 in A:
            print("7"+"1"*(N//2-1))
        elif 5 in A:
            print("5"+"1"*(N//2-2))
        elif 3 in A:
            print("3"+"1"*(N//2-2))
        elif 2 in A:
            print("2"+"1"*(N//2-2))
        else:
            print("8"+"1"*(N//2-3))
else:
    B=[[] for i in range(0,10)]
    for i in range(0,M):
        if 2 in A:
            B[5].append(2)
        if 3 in A:
            B[5].append(3)
        if 4 in A:
            B[4].append(4)
        if 5 in A:
            B[5].append(5)
        if 6 in A:
            B[6].append(6)
        if 7 in A:
            B[3].append(7)
        if 8 in A:
            B[7].append(8)
        if 9 in A:
            B[6].append(9)


    dp=['n' for i in range(0,max(10,N+1))]
    for i in range(0,min(N+1,10)):
        if i==2:
            if 2 in A:
                dp[5]='2'
        if i==3:
            if 3 in A:
                dp[5]='3'
        if i==4:
            if 4 in A:
                dp[4]='4'
        if i==5:
            if 5 in A:
                dp[5]='5'
        if i==6:
            if 6 in A:
                dp[6]='6'
        if i==7:
            if 7 in A:
                dp[3]='7'
        if i==8:
            if 8 in A:
                dp[7]='8'
        if i==9:
            if 9 in A:
                dp[6]='9'

    if N>=6:
        a='0'
        b='0'
        c='0'
        if B[3]!=[]:
            b='77'
        if dp[6]=='n':
            a=int(a)
            b=int(b)
            c=int(c)
            x=max(a,b,c)
            if x!=0:
                dp[6]=str(x)
        else:
            a=int(a)
            b=int(b)
            c=int(c)
            d=int(dp[6])
            dp[6]=str(max(a,b,c,d))

    if N>=7:
        a='0'
        b='0'
        c='0'
        d='0'
        if B[3]!=[] and dp[4]!='n':
            b='7'+dp[4]
        if B[4]!=[] and dp[3]!='n':
            c='47'
        if dp[7]=='n':
            a=int(a)
            b=int(b)
            c=int(c)
            d=int(d)
            x=max(a,b,c,d)
            if x!=0:
                dp[7]=str(x)
        else:
            a=int(a)
            b=int(b)
            c=int(c)
            d=int(d)
            e=int(dp[7])
            dp[7]=str(max(e,a,b,c,d))

    for i in range(8,N+1):
        a='0'
        b='0'
        c='0'
        d='0'
        e='0'
        f='0'
        if B[3] and dp[i-3]!='n':
            b='7'+dp[i-3]
        if B[4] and dp[i-4]!='n':
            c='4'+dp[i-4]
        if B[5] and dp[i-5]!='n':
            d=str(max(B[5]))+dp[i-5]
        if B[6] and dp[i-6]!='n':
            e=str(max(B[6]))+dp[i-6]
        if B[7] and dp[i-7]!='n':
            f='8'+dp[i-7]
        a=int(a)
        b=int(b)
        c=int(c)
        d=int(d)
        e=int(e)
        f=int(f)
        x=max(a,b,c,d,e,f)
        if x==0:
            dp[i]='n'
        else:
            dp[i]=str(x)
    print(int(dp[N])) 1 in A 1 A if N%2==0:
        print("1"*(N//2))
    else:
        if 7 in A:
            print("7"+"1"*(N//2-1))
        elif 5 in A:
            print("5"+"1"*(N//2-2))
        elif 3 in A:
            print("3"+"1"*(N//2-2))
        elif 2 in A:
            print("2"+"1"*(N//2-2))
        else:
            print("8"+"1"*(N//2-3)) N%2==0 N%2 N 2 0 print("1"*(N//2)) print "1"*(N//2) "1" N//2 N 2 if 7 in A:
            print("7"+"1"*(N//2-1))
        elif 5 in A:
            print("5"+"1"*(N//2-2))
        elif 3 in A:
            print("3"+"1"*(N//2-2))
        elif 2 in A:
            print("2"+"1"*(N//2-2))
        else:
            print("8"+"1"*(N//2-3)) 7 in A 7 A print("7"+"1"*(N//2-1)) print "7"+"1"*(N//2-1) "7" "1"*(N//2-1) "1" N//2-1 N//2 N 2 1 elif 5 in A:
            print("5"+"1"*(N//2-2))
         5 in A 5 A print("5"+"1"*(N//2-2)) print "5"+"1"*(N//2-2) "5" "1"*(N//2-2) "1" N//2-2 N//2 N 2 2 elif 3 in A:
            print("3"+"1"*(N//2-2))
         3 in A 3 A print("3"+"1"*(N//2-2)) print "3"+"1"*(N//2-2) "3" "1"*(N//2-2) "1" N//2-2 N//2 N 2 2 elif 2 in A:
            print("2"+"1"*(N//2-2))
         2 in A 2 A print("2"+"1"*(N//2-2)) print "2"+"1"*(N//2-2) "2" "1"*(N//2-2) "1" N//2-2 N//2 N 2 2 print("8"+"1"*(N//2-3)) print "8"+"1"*(N//2-3) "8" "1"*(N//2-3) "1" N//2-3 N//2 N 2 3 [] for i in range(0,10) for i in range(0,10) i range(0,10) range 0 10 for i in range(0,10) [] B=[[] for i in range(0,10)] B [[] for i in range(0,10)] for i in range(0,M):
        if 2 in A:
            B[5].append(2)
        if 3 in A:
            B[5].append(3)
        if 4 in A:
            B[4].append(4)
        if 5 in A:
            B[5].append(5)
        if 6 in A:
            B[6].append(6)
        if 7 in A:
            B[3].append(7)
        if 8 in A:
            B[7].append(8)
        if 9 in A:
            B[6].append(9)


     i range(0,M) range 0 M if 2 in A:
            B[5].append(2)
         2 in A 2 A B[5].append(2) [5].append [5] B 5 append 2 if 3 in A:
            B[5].append(3)
         3 in A 3 A B[5].append(3) [5].append [5] B 5 append 3 if 4 in A:
            B[4].append(4)
         4 in A 4 A B[4].append(4) [4].append [4] B 4 append 4 if 5 in A:
            B[5].append(5)
         5 in A 5 A B[5].append(5) [5].append [5] B 5 append 5 if 6 in A:
            B[6].append(6)
         6 in A 6 A B[6].append(6) [6].append [6] B 6 append 6 if 7 in A:
            B[3].append(7)
         7 in A 7 A B[3].append(7) [3].append [3] B 3 append 7 if 8 in A:
            B[7].append(8)
         8 in A 8 A B[7].append(8) [7].append [7] B 7 append 8 if 9 in A:
            B[6].append(9)


     9 in A 9 A B[6].append(9) [6].append [6] B 6 append 9 'n' for i in range(0,max(10,N+1)) for i in range(0,max(10,N+1)) i range(0,max(10,N+1)) range 0 max(10,N+1) max 10 N+1 N 1 for i in range(0,max(10,N+1)) 'n' dp=['n' for i in range(0,max(10,N+1))] dp ['n' for i in range(0,max(10,N+1))] for i in range(0,min(N+1,10)):
        if i==2:
            if 2 in A:
                dp[5]='2'
        if i==3:
            if 3 in A:
                dp[5]='3'
        if i==4:
            if 4 in A:
                dp[4]='4'
        if i==5:
            if 5 in A:
                dp[5]='5'
        if i==6:
            if 6 in A:
                dp[6]='6'
        if i==7:
            if 7 in A:
                dp[3]='7'
        if i==8:
            if 8 in A:
                dp[7]='8'
        if i==9:
            if 9 in A:
                dp[6]='9'

     i range(0,min(N+1,10)) range 0 min(N+1,10) min N+1 N 1 10 if i==2:
            if 2 in A:
                dp[5]='2'
         i==2 i 2 if 2 in A:
                dp[5]='2'
         2 in A 2 A dp[5]='2' dp[5] dp 5 '2' if i==3:
            if 3 in A:
                dp[5]='3'
         i==3 i 3 if 3 in A:
                dp[5]='3'
         3 in A 3 A dp[5]='3' dp[5] dp 5 '3' if i==4:
            if 4 in A:
                dp[4]='4'
         i==4 i 4 if 4 in A:
                dp[4]='4'
         4 in A 4 A dp[4]='4' dp[4] dp 4 '4' if i==5:
            if 5 in A:
                dp[5]='5'
         i==5 i 5 if 5 in A:
                dp[5]='5'
         5 in A 5 A dp[5]='5' dp[5] dp 5 '5' if i==6:
            if 6 in A:
                dp[6]='6'
         i==6 i 6 if 6 in A:
                dp[6]='6'
         6 in A 6 A dp[6]='6' dp[6] dp 6 '6' if i==7:
            if 7 in A:
                dp[3]='7'
         i==7 i 7 if 7 in A:
                dp[3]='7'
         7 in A 7 A dp[3]='7' dp[3] dp 3 '7' if i==8:
            if 8 in A:
                dp[7]='8'
         i==8 i 8 if 8 in A:
                dp[7]='8'
         8 in A 8 A dp[7]='8' dp[7] dp 7 '8' if i==9:
            if 9 in A:
                dp[6]='9'

     i==9 i 9 if 9 in A:
                dp[6]='9'

     9 in A 9 A dp[6]='9' dp[6] dp 6 '9' if N>=6:
        a='0'
        b='0'
        c='0'
        if B[3]!=[]:
            b='77'
        if dp[6]=='n':
            a=int(a)
            b=int(b)
            c=int(c)
            x=max(a,b,c)
            if x!=0:
                dp[6]=str(x)
        else:
            a=int(a)
            b=int(b)
            c=int(c)
            d=int(dp[6])
            dp[6]=str(max(a,b,c,d))

     N>=6 N 6 a='0' a '0' b='0' b '0' c='0' c '0' if B[3]!=[]:
            b='77'
         B[3]!=[] B[3] B 3 [] b='77' b '77' if dp[6]=='n':
            a=int(a)
            b=int(b)
            c=int(c)
            x=max(a,b,c)
            if x!=0:
                dp[6]=str(x)
        else:
            a=int(a)
            b=int(b)
            c=int(c)
            d=int(dp[6])
            dp[6]=str(max(a,b,c,d))

     dp[6]=='n' dp[6] dp 6 'n' a=int(a) a int(a) int a b=int(b) b int(b) int b c=int(c) c int(c) int c x=max(a,b,c) x max(a,b,c) max a b c if x!=0:
                dp[6]=str(x)
         x!=0 x 0 dp[6]=str(x) dp[6] dp 6 str(x) str x a=int(a) a int(a) int a b=int(b) b int(b) int b c=int(c) c int(c) int c d=int(dp[6]) d int(dp[6]) int dp[6] dp 6 dp[6]=str(max(a,b,c,d)) dp[6] dp 6 str(max(a,b,c,d)) str max(a,b,c,d) max a b c d if N>=7:
        a='0'
        b='0'
        c='0'
        d='0'
        if B[3]!=[] and dp[4]!='n':
            b='7'+dp[4]
        if B[4]!=[] and dp[3]!='n':
            c='47'
        if dp[7]=='n':
            a=int(a)
            b=int(b)
            c=int(c)
            d=int(d)
            x=max(a,b,c,d)
            if x!=0:
                dp[7]=str(x)
        else:
            a=int(a)
            b=int(b)
            c=int(c)
            d=int(d)
            e=int(dp[7])
            dp[7]=str(max(e,a,b,c,d))

     N>=7 N 7 a='0' a '0' b='0' b '0' c='0' c '0' d='0' d '0' if B[3]!=[] and dp[4]!='n':
            b='7'+dp[4]
         B[3]!=[] and dp[4]!='n' B[3]!=[] B[3] B 3 [] dp[4]!='n' dp[4] dp 4 'n' b='7'+dp[4] b '7'+dp[4] '7' dp[4] dp 4 if B[4]!=[] and dp[3]!='n':
            c='47'
         B[4]!=[] and dp[3]!='n' B[4]!=[] B[4] B 4 [] dp[3]!='n' dp[3] dp 3 'n' c='47' c '47' if dp[7]=='n':
            a=int(a)
            b=int(b)
            c=int(c)
            d=int(d)
            x=max(a,b,c,d)
            if x!=0:
                dp[7]=str(x)
        else:
            a=int(a)
            b=int(b)
            c=int(c)
            d=int(d)
            e=int(dp[7])
            dp[7]=str(max(e,a,b,c,d))

     dp[7]=='n' dp[7] dp 7 'n' a=int(a) a int(a) int a b=int(b) b int(b) int b c=int(c) c int(c) int c d=int(d) d int(d) int d x=max(a,b,c,d) x max(a,b,c,d) max a b c d if x!=0:
                dp[7]=str(x)
         x!=0 x 0 dp[7]=str(x) dp[7] dp 7 str(x) str x a=int(a) a int(a) int a b=int(b) b int(b) int b c=int(c) c int(c) int c d=int(d) d int(d) int d e=int(dp[7]) e int(dp[7]) int dp[7] dp 7 dp[7]=str(max(e,a,b,c,d)) dp[7] dp 7 str(max(e,a,b,c,d)) str max(e,a,b,c,d) max e a b c d for i in range(8,N+1):
        a='0'
        b='0'
        c='0'
        d='0'
        e='0'
        f='0'
        if B[3] and dp[i-3]!='n':
            b='7'+dp[i-3]
        if B[4] and dp[i-4]!='n':
            c='4'+dp[i-4]
        if B[5] and dp[i-5]!='n':
            d=str(max(B[5]))+dp[i-5]
        if B[6] and dp[i-6]!='n':
            e=str(max(B[6]))+dp[i-6]
        if B[7] and dp[i-7]!='n':
            f='8'+dp[i-7]
        a=int(a)
        b=int(b)
        c=int(c)
        d=int(d)
        e=int(e)
        f=int(f)
        x=max(a,b,c,d,e,f)
        if x==0:
            dp[i]='n'
        else:
            dp[i]=str(x)
     i range(8,N+1) range 8 N+1 N 1 a='0' a '0' b='0' b '0' c='0' c '0' d='0' d '0' e='0' e '0' f='0' f '0' if B[3] and dp[i-3]!='n':
            b='7'+dp[i-3]
         B[3] and dp[i-3]!='n' B[3] B 3 dp[i-3]!='n' dp[i-3] dp i-3 i 3 'n' b='7'+dp[i-3] b '7'+dp[i-3] '7' dp[i-3] dp i-3 i 3 if B[4] and dp[i-4]!='n':
            c='4'+dp[i-4]
         B[4] and dp[i-4]!='n' B[4] B 4 dp[i-4]!='n' dp[i-4] dp i-4 i 4 'n' c='4'+dp[i-4] c '4'+dp[i-4] '4' dp[i-4] dp i-4 i 4 if B[5] and dp[i-5]!='n':
            d=str(max(B[5]))+dp[i-5]
         B[5] and dp[i-5]!='n' B[5] B 5 dp[i-5]!='n' dp[i-5] dp i-5 i 5 'n' d=str(max(B[5]))+dp[i-5] d str(max(B[5]))+dp[i-5] str(max(B[5])) str max(B[5]) max B[5] B 5 dp[i-5] dp i-5 i 5 if B[6] and dp[i-6]!='n':
            e=str(max(B[6]))+dp[i-6]
         B[6] and dp[i-6]!='n' B[6] B 6 dp[i-6]!='n' dp[i-6] dp i-6 i 6 'n' e=str(max(B[6]))+dp[i-6] e str(max(B[6]))+dp[i-6] str(max(B[6])) str max(B[6]) max B[6] B 6 dp[i-6] dp i-6 i 6 if B[7] and dp[i-7]!='n':
            f='8'+dp[i-7]
         B[7] and dp[i-7]!='n' B[7] B 7 dp[i-7]!='n' dp[i-7] dp i-7 i 7 'n' f='8'+dp[i-7] f '8'+dp[i-7] '8' dp[i-7] dp i-7 i 7 a=int(a) a int(a) int a b=int(b) b int(b) int b c=int(c) c int(c) int c d=int(d) d int(d) int d e=int(e) e int(e) int e f=int(f) f int(f) int f x=max(a,b,c,d,e,f) x max(a,b,c,d,e,f) max a b c d e f if x==0:
            dp[i]='n'
        else:
            dp[i]=str(x)
     x==0 x 0 dp[i]='n' dp[i] dp i 'n' dp[i]=str(x) dp[i] dp i str(x) str x print(int(dp[N])) print int(dp[N]) int dp[N] dp N d=int(d) int(d) d d=int(d) int(d) d a='0' '0' a b=int(b) int(b) b d=int(d) int(d) d e=str(max(B[6]))+dp[i-6] str(max(B[6]))+dp[i-6] e A=list(map(int,input().split())) list(map(int,input().split())) A c=int(c) int(c) c f=int(f) int(f) f e=int(e) int(e) e f='8'+dp[i-7] '8'+dp[i-7] f d=int(dp[6]) int(dp[6]) d b='77' '77' b d=str(max(B[5]))+dp[i-5] str(max(B[5]))+dp[i-5] d N,M=map(int,input().split()) map(int,input().split()) N a='0' '0' a c='4'+dp[i-4] '4'+dp[i-4] c b=int(b) int(b) b b=int(b) int(b) b c=int(c) int(c) c a=int(a) int(a) a b=int(b) int(b) b c='47' '47' c a='0' '0' a c=int(c) int(c) c dp=['n' for i in range(0,max(10,N+1))] ['n' for i in range(0,max(10,N+1))] dp e='0' '0' e a=int(a) int(a) a d='0' '0' d b=int(b) int(b) b b='7'+dp[i-3] '7'+dp[i-3] b c=int(c) int(c) c c=int(c) int(c) c M=map(int,input().split()) map(int,input().split()) M d='0' '0' d c='0' '0' c a=int(a) int(a) a b='0' '0' b f='0' '0' f a=int(a) int(a) a x=max(a,b,c) max(a,b,c) x b='7'+dp[4] '7'+dp[4] b c='0' '0' c b='0' '0' b b='0' '0' b x=max(a,b,c,d) max(a,b,c,d) x e=int(dp[7]) int(dp[7]) e x=max(a,b,c,d,e,f) max(a,b,c,d,e,f) x a=int(a) int(a) a c='0' '0' c B=[[] for i in range(0,10)] [[] for i in range(0,10)] B
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()

if 1 in A:
    if N%2==0:
        print("1"*(N//2))
    else:
        if 7 in A:
            print("7"+"1"*(N//2-1))
        elif 5 in A:
            print("5"+"1"*(N//2-2))
        elif 3 in A:
            print("3"+"1"*(N//2-2))
        elif 2 in A:
            print("2"+"1"*(N//2-2))
        else:
            print("8"+"1"*(N//2-3))
else:
    B=[[] for i in range(0,10)]
    for i in range(0,M):
        if 2 in A:
            B[5].append(2)
        if 3 in A:
            B[5].append(3)
        if 4 in A:
            B[4].append(4)
        if 5 in A:
            B[5].append(5)
        if 6 in A:
            B[6].append(6)
        if 7 in A:
            B[3].append(7)
        if 8 in A:
            B[7].append(8)
        if 9 in A:
            B[6].append(9)


    dp=['n' for i in range(0,max(10,N+1))]
    for i in range(0,min(N+1,10)):
        if i==2:
            if 2 in A:
                dp[5]='2'
        if i==3:
            if 3 in A:
                dp[5]='3'
        if i==4:
            if 4 in A:
                dp[4]='4'
        if i==5:
            if 5 in A:
                dp[5]='5'
        if i==6:
            if 6 in A:
                dp[6]='6'
        if i==7:
            if 7 in A:
                dp[3]='7'
        if i==8:
            if 8 in A:
                dp[7]='8'
        if i==9:
            if 9 in A:
                dp[6]='9'

    if N>=6:
        a='0'
        b='0'
        c='0'
        if B[3]!=[]:
            b='77'
        if dp[6]=='n':
            a=int(a)
            b=int(b)
            c=int(c)
            x=max(a,b,c)
            if x!=0:
                dp[6]=str(x)
        else:
            a=int(a)
            b=int(b)
            c=int(c)
            d=int(dp[6])
            dp[6]=str(max(a,b,c,d))

    if N>=7:
        a='0'
        b='0'
        c='0'
        d='0'
        if B[3]!=[] and dp[4]!='n':
            b='7'+dp[4]
        if B[4]!=[] and dp[3]!='n':
            c='47'
        if dp[7]=='n':
            a=int(a)
            b=int(b)
            c=int(c)
            d=int(d)
            x=max(a,b,c,d)
            if x!=0:
                dp[7]=str(x)
        else:
            a=int(a)
            b=int(b)
            c=int(c)
            d=int(d)
            e=int(dp[7])
            dp[7]=str(max(e,a,b,c,d))

    for i in range(8,N+1):
        a='0'
        b='0'
        c='0'
        d='0'
        e='0'
        f='0'
        if B[3] and dp[i-3]!='n':
            b='7'+dp[i-3]
        if B[4] and dp[i-4]!='n':
            c='4'+dp[i-4]
        if B[5] and dp[i-5]!='n':
            d=str(max(B[5]))+dp[i-5]
        if B[6] and dp[i-6]!='n':
            e=str(max(B[6]))+dp[i-6]
        if B[7] and dp[i-7]!='n':
            f='8'+dp[i-7]
        a=int(a)
        b=int(b)
        c=int(c)
        d=int(d)
        e=int(e)
        f=int(f)
        x=max(a,b,c,d,e,f)
        if x==0:
            dp[i]='n'
        else:
            dp[i]=str(x)
    print(int(dp[N]))
