n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
nums=[0,2,5,5,4,5,6,3,7,6]
dp=[-1]*(n+1)
dp[0]=0
for i in range(1,n+1):
    for x in a:
        if i-nums[x]>=0:
            dp[i]=max(dp[i-nums[x]]+1,dp[i])
k=dp[n]
ans=[]
for i in range(k):
    for x in a:
        if n-nums[x]<0:
            continue
        if dp[n-nums[x]]==dp[n]-1:
            n-=nums[x]
            ans.append(x)
            break
print("".join(list(map(str,ans)))) 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(reverse=True) a.sort a sort reverse=True reverse True nums=[0,2,5,5,4,5,6,3,7,6] nums [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 dp=[-1]*(n+1) dp [-1]*(n+1) [-1] -1 n+1 n 1 dp[0]=0 dp[0] dp 0 0 for i in range(1,n+1):
    for x in a:
        if i-nums[x]>=0:
            dp[i]=max(dp[i-nums[x]]+1,dp[i]) i range(1,n+1) range 1 n+1 n 1 for x in a:
        if i-nums[x]>=0:
            dp[i]=max(dp[i-nums[x]]+1,dp[i]) x a if i-nums[x]>=0:
            dp[i]=max(dp[i-nums[x]]+1,dp[i]) i-nums[x]>=0 i-nums[x] i nums[x] nums x 0 dp[i]=max(dp[i-nums[x]]+1,dp[i]) dp[i] dp i max(dp[i-nums[x]]+1,dp[i]) max dp[i-nums[x]]+1 dp[i-nums[x]] dp i-nums[x] i nums[x] nums x 1 dp[i] dp i k=dp[n] k dp[n] dp n ans=[] ans [] for i in range(k):
    for x in a:
        if n-nums[x]<0:
            continue
        if dp[n-nums[x]]==dp[n]-1:
            n-=nums[x]
            ans.append(x)
            break i range(k) range k for x in a:
        if n-nums[x]<0:
            continue
        if dp[n-nums[x]]==dp[n]-1:
            n-=nums[x]
            ans.append(x)
            break x a if n-nums[x]<0:
            continue
         n-nums[x]<0 n-nums[x] n nums[x] nums x 0 continue if dp[n-nums[x]]==dp[n]-1:
            n-=nums[x]
            ans.append(x)
            break dp[n-nums[x]]==dp[n]-1 dp[n-nums[x]] dp n-nums[x] n nums[x] nums x dp[n]-1 dp[n] dp n 1 n-=nums[x] n nums[x] nums x ans.append(x) ans.append ans append x break print("".join(list(map(str,ans)))) print "".join(list(map(str,ans))) "".join "" join list(map(str,ans)) list map(str,ans) map str ans dp=[-1]*(n+1) [-1]*(n+1) dp n-=nums[x] nums[x] n a=list(map(int,input().split())) list(map(int,input().split())) a k=dp[n] dp[n] k ans=[] [] ans n,m=map(int,input().split()) map(int,input().split()) n m=map(int,input().split()) map(int,input().split()) m nums=[0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] nums
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
nums=[0,2,5,5,4,5,6,3,7,6]
dp=[-1]*(n+1)
dp[0]=0
for i in range(1,n+1):
    for x in a:
        if i-nums[x]>=0:
            dp[i]=max(dp[i-nums[x]]+1,dp[i])
k=dp[n]
ans=[]
for i in range(k):
    for x in a:
        if n-nums[x]<0:
            continue
        if dp[n-nums[x]]==dp[n]-1:
            n-=nums[x]
            ans.append(x)
            break
print("".join(list(map(str,ans))))
