Buggy python submission (verdict: Runtime Error):
match_num=[0,2,5,5,4,5,6,3,7,6]
N,M=map(int, input().split())
nums=sorted(list(map(int, input().split())),reverse=True)
INF=1000000
#max桁数
dp = [-INF for _ in range(N+1)]
dp[0]=0
usables=[]
for n in nums:
  usables.append(match_num[n])

for i in range(min(usables), N+1):
  tmp=[]
  for u in usables:
    if (i-u)>=0:
      tmp.append(dp[i-u])
  
  dp[i]=max(tmp)+1

remained_maches=N

ans=''  
for i in range(dp[N]):
  for j in range(M):
    if dp[remained_maches]-1==dp[remained_maches-usables[j]]:
      ans+=str(nums[j])
      remained_maches-=usables[j]
      break
        
print(ans)



Fixed submission:
match_num=[0,2,5,5,4,5,6,3,7,6]
N,M=map(int, input().split())
nums=sorted(list(map(int, input().split())),reverse=True)
INF=1000000
#max桁数
dp = [-INF for _ in range(N+1)]
dp[0]=0
usables=[]
for n in nums:
  usables.append(match_num[n])

for i in range(min(usables), N+1):
  tmp=[]
  for u in usables:
    if (i-u)>=0:
      tmp.append(dp[i-u])
  
  dp[i]=max(tmp)+1

remained_maches=N

ans=''  
for i in range(dp[N]):
  for j in range(M):
    if (remained_maches-usables[j])>=0:
      if dp[remained_maches]-1==dp[remained_maches-usables[j]]:
        ans+=str(nums[j])
        remained_maches-=usables[j]
        break
        
print(ans)

Buggy python submission (verdict: Runtime Error):
match_num=[0,2,5,5,4,5,6,3,7,6]
N,M=map(int, input().split())
nums=sorted(list(map(int, input().split())),reverse=True)
INF=1000000
#max桁数
dp = [-INF for _ in range(N+1)]
dp[0]=0
usables=[]
for n in nums:
  usables.append(match_num[n])

for i in range(min(usables), N+1):
  tmp=[]
  for u in usables:
    if(i-u)>=0:
      tmp.append(dp[i-u])
  
  dp[i]=max(tmp)+1

remained_maches=N

ans=''  
for i in range(dp[N]):
  for j in range(M):
    if dp[remained_maches]-1==dp[remained_maches-usables[j]]:
      ans+=str(nums[j])
      remained_maches-=usables[j]
      break

print(dp)
print(ans)



Fixed submission:
match_num=[0,2,5,5,4,5,6,3,7,6]
N,M=map(int, input().split())
nums=sorted(list(map(int, input().split())),reverse=True)
INF=1000000
#max桁数
dp = [-INF for _ in range(N+1)]
dp[0]=0
usables=[]
for n in nums:
  usables.append(match_num[n])

for i in range(min(usables), N+1):
  tmp=[]
  for u in usables:
    if (i-u)>=0:
      tmp.append(dp[i-u])
  
  dp[i]=max(tmp)+1

remained_maches=N

ans=''  
for i in range(dp[N]):
  for j in range(M):
    if (remained_maches-usables[j])>=0:
      if dp[remained_maches]-1==dp[remained_maches-usables[j]]:
        ans+=str(nums[j])
        remained_maches-=usables[j]
        break
        
print(ans)

Buggy python submission (verdict: Runtime Error):
match_num=[0,2,5,5,4,5,6,3,7,6]
N,M=map(int, input().split())
nums=sorted(list(map(int, input().split())),reverse=True)
INF=1000000
#max桁数
dp = [-INF for _ in range(N+1)]
dp[0]=0
usables=[]
for n in nums:
  usables.append(match_num[n])

for i in range(min(usables), N+1):
  tmp=[]
  for u in usables:
    tmp.append(dp[i-u])
  
  dp[i]=max(tmp)+1

remained_maches=N

ans=''  
for i in range(dp[N]):
  for j in range(M):
    if remained_maches-usables[j]>=0 :
      if dp[remained_maches]-1==dp[remained_maches-usables[j]]:
        ans+=str(nums[j])
        remained_maches-=usables[j]
        break
print(ans)



Fixed submission:
match_num=[0,2,5,5,4,5,6,3,7,6]
N,M=map(int, input().split())
nums=sorted(list(map(int, input().split())),reverse=True)
INF=1000000
#max桁数
dp = [-INF for _ in range(N+1)]
dp[0]=0
usables=[]
for n in nums:
  usables.append(match_num[n])

for i in range(min(usables), N+1):
  tmp=[]
  for u in usables:
    if (i-u)>=0:
      tmp.append(dp[i-u])
  
  dp[i]=max(tmp)+1

remained_maches=N

ans=''  
for i in range(dp[N]):
  for j in range(M):
    if (remained_maches-usables[j])>=0:
      if dp[remained_maches]-1==dp[remained_maches-usables[j]]:
        ans+=str(nums[j])
        remained_maches-=usables[j]
        break
        
print(ans)

Buggy python submission (verdict: Runtime Error):
match_num=[0,2,5,5,4,5,6,3,7,6]
N,M=map(int, input().split())
nums=sorted(list(map(int, input().split())),reverse=True)
INF=1000000
#max桁数
dp = [-INF for _ in range(N+1)]
dp[0]=0
usables=[]
for n in nums:
  usables.append(match_num[n])

for i in range(min(usables), N+1):
  tmp=[]
  for u in usables:
    tmp.append(dp[i-u])
  
  dp[i]=max(tmp)+1

remained_maches=N

ans=''  
for i in range(dp[N]):
  for j in range(M):
    if dp[remained_maches]-1==dp[remained_maches-usables[j]]:
      ans+=str(nums[j])
      remained_maches-=usables[j]
      break
      
print(ans)

Fixed submission:
match_num=[0,2,5,5,4,5,6,3,7,6]
N,M=map(int, input().split())
nums=sorted(list(map(int, input().split())),reverse=True)
INF=1000000
#max桁数
dp = [-INF for _ in range(N+1)]
dp[0]=0
usables=[]
for n in nums:
  usables.append(match_num[n])

for i in range(min(usables), N+1):
  tmp=[]
  for u in usables:
    if (i-u)>=0:
      tmp.append(dp[i-u])
  
  dp[i]=max(tmp)+1

remained_maches=N

ans=''  
for i in range(dp[N]):
  for j in range(M):
    if (remained_maches-usables[j])>=0:
      if dp[remained_maches]-1==dp[remained_maches-usables[j]]:
        ans+=str(nums[j])
        remained_maches-=usables[j]
        break
        
print(ans)