N,M = map(int,input().split())
A = list(map(int,input().split()))
num = {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}

def lenmax(a,b):
    if len(a) > len(b):
        return a
    elif len(a) < len(b):
        return b
    return max(a,b)

dp = ['-' for i in range(10**4+10)]
dp[0] = ''
for i in range(N+1):
    if dp[i] == '-':
        continue
    for a in A:
        dp[i+num[a]] = lenmax(dp[i+num[a]],dp[i]+str(a))
print(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 num = {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6} num {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6} 1 1 2 2 2 5 3 3 5 4 4 4 5 5 5 6 6 6 7 7 3 8 8 7 9 9 6 def lenmax(a,b):
    if len(a) > len(b):
        return a
    elif len(a) < len(b):
        return b
    return max(a,b) lenmax if len(a) > len(b):
        return a
    elif len(a) < len(b):
        return b
     len(a) > len(b) len(a) len a len(b) len b return a a elif len(a) < len(b):
        return b
     len(a) < len(b) len(a) len a len(b) len b return b b return max(a,b) max(a,b) max a b a a b b '-' for i in range(10**4+10) for i in range(10**4+10) i range(10**4+10) range 10**4+10 10**4 10 4 10 for i in range(10**4+10) '-' dp = ['-' for i in range(10**4+10)] dp ['-' for i in range(10**4+10)] dp[0] = '' dp[0] dp 0 '' for i in range(N+1):
    if dp[i] == '-':
        continue
    for a in A:
        dp[i+num[a]] = lenmax(dp[i+num[a]],dp[i]+str(a)) i range(N+1) range N+1 N 1 if dp[i] == '-':
        continue
     dp[i] == '-' dp[i] dp i '-' continue for a in A:
        dp[i+num[a]] = lenmax(dp[i+num[a]],dp[i]+str(a)) a A dp[i+num[a]] = lenmax(dp[i+num[a]],dp[i]+str(a)) dp[i+num[a]] dp i+num[a] i num[a] num a lenmax(dp[i+num[a]],dp[i]+str(a)) lenmax dp[i+num[a]] dp i+num[a] i num[a] num a dp[i]+str(a) dp[i] dp i str(a) str a print(dp[N]) print dp[N] dp N num = {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6} {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6} num A = list(map(int,input().split())) list(map(int,input().split())) A def lenmax(a,b):
    if len(a) > len(b):
        return a
    elif len(a) < len(b):
        return b
    return max(a,b) def lenmax(a,b):
    if len(a) > len(b):
        return a
    elif len(a) < len(b):
        return b
    return max(a,b) lenmax M = map(int,input().split()) map(int,input().split()) M dp = ['-' for i in range(10**4+10)] ['-' for i in range(10**4+10)] dp N,M = map(int,input().split()) map(int,input().split()) N
N,M = map(int,input().split())
A = list(map(int,input().split()))
num = {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}

def lenmax(a,b):
    if len(a) > len(b):
        return a
    elif len(a) < len(b):
        return b
    return max(a,b)

dp = ['-' for i in range(10**4+10)]
dp[0] = ''
for i in range(N+1):
    if dp[i] == '-':
        continue
    for a in A:
        dp[i+num[a]] = lenmax(dp[i+num[a]],dp[i]+str(a))
print(dp[N])