n,m=map(int, input().split())
List=list(map(int, input().split()))
d=[0]*n*9+[-1]*n*9
#print(d)
for i in range(1, n+1):
    d[i]=max(d[i-int("0255456376"[a])]*10+a for a in List)
print(d[n]) n,m=map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m List=list(map(int, input().split())) List list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split d=[0]*n*9+[-1]*n*9 d [0]*n*9+[-1]*n*9 [0]*n*9 [0]*n [0] 0 n 9 [-1]*n*9 [-1]*n [-1] -1 n 9 for i in range(1, n+1):
    d[i]=max(d[i-int("0255456376"[a])]*10+a for a in List) i range(1, n+1) range 1 n+1 n 1 d[i]=max(d[i-int("0255456376"[a])]*10+a for a in List) d[i] d i max(d[i-int("0255456376"[a])]*10+a for a in List) max d[i-int("0255456376"[a])]*10+a d[i-int("0255456376"[a])]*10 d[i-int("0255456376"[a])] d i-int("0255456376"[a]) i int("0255456376"[a]) int "0255456376"[a] "0255456376" a 10 a print(d[n]) print d[n] d n List=list(map(int, input().split())) list(map(int, input().split())) List m=map(int, input().split()) map(int, input().split()) m n,m=map(int, input().split()) map(int, input().split()) n d=[0]*n*9+[-1]*n*9 [0]*n*9+[-1]*n*9 d
n,m=map(int, input().split())
List=list(map(int, input().split()))
d=[0]*n*9+[-1]*n*9
#print(d)
for i in range(1, n+1):
    d[i]=max(d[i-int("0255456376"[a])]*10+a for a in List)
print(d[n])
