n , m = map(int, input().split(' '))
s = [0,2,5,5,4,5,6,3,7,6]
a = list(map(int, input().split(' ')))
r = []
for i in range(len(a)):
    r.append([s[a[i]],a[i]])
r.sort()
d = [-1]*(n+1)
d[0] = 0
for i in range(1,n+1):
    j = 0
    while j < len(a):
        if i-s[r[j][1]] < 0:
            j += 1
        elif d[i-s[r[j][1]]] >= 0:
            d[i] = d[i-s[r[j][1]]] +1
            break
        else:
            j+= 1
result = []
a.sort(reverse = True)
while n > 0:
    j = 0
    while j < len(a):
        if n < s[a[j]]:
            j += 1
        elif d[n-s[a[j]]] +1 == d[n]:
            result.append(a[j])
            n -= s[a[j]]
            break
        else:
            j += 1
print(''.join(list(map(str, result)))) n , m = map(int, input().split(' ')) n map(int, input().split(' ')) map int input().split(' ') ().split () input split ' ' m s = [0,2,5,5,4,5,6,3,7,6] s [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 a = list(map(int, input().split(' '))) a list(map(int, input().split(' '))) list map(int, input().split(' ')) map int input().split(' ') ().split () input split ' ' r = [] r [] for i in range(len(a)):
    r.append([s[a[i]],a[i]]) i range(len(a)) range len(a) len a r.append([s[a[i]],a[i]]) r.append r append [s[a[i]],a[i]] s[a[i]] s a[i] a i a[i] a i r.sort() r.sort r sort d = [-1]*(n+1) d [-1]*(n+1) [-1] -1 n+1 n 1 d[0] = 0 d[0] d 0 0 for i in range(1,n+1):
    j = 0
    while j < len(a):
        if i-s[r[j][1]] < 0:
            j += 1
        elif d[i-s[r[j][1]]] >= 0:
            d[i] = d[i-s[r[j][1]]] +1
            break
        else:
            j+= 1 i range(1,n+1) range 1 n+1 n 1 j = 0 j 0 while j < len(a):
        if i-s[r[j][1]] < 0:
            j += 1
        elif d[i-s[r[j][1]]] >= 0:
            d[i] = d[i-s[r[j][1]]] +1
            break
        else:
            j+= 1 j < len(a) j len(a) len a if i-s[r[j][1]] < 0:
            j += 1
        elif d[i-s[r[j][1]]] >= 0:
            d[i] = d[i-s[r[j][1]]] +1
            break
        else:
            j+= 1 i-s[r[j][1]] < 0 i-s[r[j][1]] i s[r[j][1]] s r[j][1] [j] r j 1 0 j += 1 j 1 elif d[i-s[r[j][1]]] >= 0:
            d[i] = d[i-s[r[j][1]]] +1
            break
         d[i-s[r[j][1]]] >= 0 d[i-s[r[j][1]]] d i-s[r[j][1]] i s[r[j][1]] s r[j][1] [j] r j 1 0 d[i] = d[i-s[r[j][1]]] +1 d[i] d i d[i-s[r[j][1]]] +1 d[i-s[r[j][1]]] d i-s[r[j][1]] i s[r[j][1]] s r[j][1] [j] r j 1 1 break j+= 1 j 1 result = [] result [] a.sort(reverse = True) a.sort a sort reverse = True reverse True while n > 0:
    j = 0
    while j < len(a):
        if n < s[a[j]]:
            j += 1
        elif d[n-s[a[j]]] +1 == d[n]:
            result.append(a[j])
            n -= s[a[j]]
            break
        else:
            j += 1 n > 0 n 0 j = 0 j 0 while j < len(a):
        if n < s[a[j]]:
            j += 1
        elif d[n-s[a[j]]] +1 == d[n]:
            result.append(a[j])
            n -= s[a[j]]
            break
        else:
            j += 1 j < len(a) j len(a) len a if n < s[a[j]]:
            j += 1
        elif d[n-s[a[j]]] +1 == d[n]:
            result.append(a[j])
            n -= s[a[j]]
            break
        else:
            j += 1 n < s[a[j]] n s[a[j]] s a[j] a j j += 1 j 1 elif d[n-s[a[j]]] +1 == d[n]:
            result.append(a[j])
            n -= s[a[j]]
            break
         d[n-s[a[j]]] +1 == d[n] d[n-s[a[j]]] +1 d[n-s[a[j]]] d n-s[a[j]] n s[a[j]] s a[j] a j 1 d[n] d n result.append(a[j]) result.append result append a[j] a j n -= s[a[j]] n s[a[j]] s a[j] a j break j += 1 j 1 print(''.join(list(map(str, result)))) print ''.join(list(map(str, result))) ''.join '' join list(map(str, result)) list map(str, result) map str result m = map(int, input().split(' ')) map(int, input().split(' ')) m result = [] [] result j = 0 0 j j += 1 1 j j += 1 1 j n , m = map(int, input().split(' ')) map(int, input().split(' ')) n d = [-1]*(n+1) [-1]*(n+1) d n -= s[a[j]] s[a[j]] n r = [] [] r j+= 1 1 j j += 1 1 j j = 0 0 j s = [0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] s a = list(map(int, input().split(' '))) list(map(int, input().split(' '))) a
n , m = map(int, input().split(' '))
s = [0,2,5,5,4,5,6,3,7,6]
a = list(map(int, input().split(' ')))
r = []
for i in range(len(a)):
    r.append([s[a[i]],a[i]])
r.sort()
d = [-1]*(n+1)
d[0] = 0
for i in range(1,n+1):
    j = 0
    while j < len(a):
        if i-s[r[j][1]] < 0:
            j += 1
        elif d[i-s[r[j][1]]] >= 0:
            d[i] = d[i-s[r[j][1]]] +1
            break
        else:
            j+= 1
result = []
a.sort(reverse = True)
while n > 0:
    j = 0
    while j < len(a):
        if n < s[a[j]]:
            j += 1
        elif d[n-s[a[j]]] +1 == d[n]:
            result.append(a[j])
            n -= s[a[j]]
            break
        else:
            j += 1
print(''.join(list(map(str, result))))