n, m = map(int, input().split())
a = list(map(int, input().split()))

maxnum = [-1] * (n+1)
cost = [0,2,5,5,4,5,6,3,7,6]
maxnum[0] = 0
for i in range(n+1):
    for num in a:
        if ( i+cost[num] < n+1 ):
            maxnum[i+cost[num]] = max(maxnum[i+cost[num]], num + maxnum[i]*10)

print(maxnum[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 maxnum = [-1] * (n+1) maxnum [-1] * (n+1) [-1] -1 n+1 n 1 cost = [0,2,5,5,4,5,6,3,7,6] cost [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 maxnum[0] = 0 maxnum[0] maxnum 0 0 for i in range(n+1):
    for num in a:
        if ( i+cost[num] < n+1 ):
            maxnum[i+cost[num]] = max(maxnum[i+cost[num]], num + maxnum[i]*10) i range(n+1) range n+1 n 1 for num in a:
        if ( i+cost[num] < n+1 ):
            maxnum[i+cost[num]] = max(maxnum[i+cost[num]], num + maxnum[i]*10) num a if ( i+cost[num] < n+1 ):
            maxnum[i+cost[num]] = max(maxnum[i+cost[num]], num + maxnum[i]*10) i+cost[num] < n+1 i+cost[num] i cost[num] cost num n+1 n 1 maxnum[i+cost[num]] = max(maxnum[i+cost[num]], num + maxnum[i]*10) maxnum[i+cost[num]] maxnum i+cost[num] i cost[num] cost num max(maxnum[i+cost[num]], num + maxnum[i]*10) max maxnum[i+cost[num]] maxnum i+cost[num] i cost[num] cost num num + maxnum[i]*10 num maxnum[i]*10 maxnum[i] maxnum i 10 print(maxnum[n]) print maxnum[n] maxnum n a = list(map(int, input().split())) list(map(int, input().split())) a n, m = map(int, input().split()) map(int, input().split()) n cost = [0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] cost maxnum = [-1] * (n+1) [-1] * (n+1) maxnum m = map(int, input().split()) map(int, input().split()) m
n, m = map(int, input().split())
a = list(map(int, input().split()))

maxnum = [-1] * (n+1)
cost = [0,2,5,5,4,5,6,3,7,6]
maxnum[0] = 0
for i in range(n+1):
    for num in a:
        if ( i+cost[num] < n+1 ):
            maxnum[i+cost[num]] = max(maxnum[i+cost[num]], num + maxnum[i]*10)

print(maxnum[n])