Buggy python submission (verdict: Time Limit Exceeded):
H,N=map(int, input().split())
A=[]
B=[]

import numpy as np
  


for n in range(N):
  a,b=map(int, input().split())
  A.append(a)
  B.append(b)

dp=[float('inf')]*(H+1)
dp[0]=0
for h in range(1,H+1):
  for i in range(N):
    if h-A[i]>=0:
      dp[h]=min(dp[h-A[i]]+B[i],dp[h])
    else:
      dp[h]=min(dp[h],B[i])
print(dp[H])

Fixed submission:
H,N=map(int, input().split())
A=[]
B=[]

dp=[10**10]*(H+1)
dp[0]=0
for n in range(N):
  a,b=map(int, input().split())
  A.append(a)
  B.append(b)
    
for h in range(1,H+1):
  for n in range(N):
    if h-A[n]>=0:
      dp[h]=min(dp[h],dp[h-A[n]]+B[n])
    else:
      dp[h]=min(dp[h],B[n])
print(dp[H])

Buggy python submission (verdict: Runtime Error):
H,N=map(int, input().split())
import math



MAX=10**4+1
def solve(r,idx):
  if idx==N:
    return MAX
  if r%A[idx][1]==0:
    return (r//A[idx][1])*A[idx][2]
  else:
    return min((r//A[idx][1]+1)*A[idx][2],(r//A[idx][1])*A[idx][2]+solve(r%A[idx][1],idx+1))

def main():
  A=[]
  B=[]
  for i in range(N):
    a,b=map(int, input().split())
    A.append([a/b,a,b])
  if N==1:
    if H%A[0][1]==0:
    	print((H//A[0][1])*A[0][2])
    else:
    	print((H//A[0][1]+1)*A[0][2])
    return
  A=sorted(A)[::-1]

  if H%A[0][1]==0:
    print((H//A[0][1])*A[0][2])
  else:
    ans=min((H//A[0][1]+1)*A[0][2],(H//A[0][1])*A[0][2]+solve(H%A[0][1],1))
    print(ans)

main()

Fixed submission:
H,N=map(int, input().split())
A=[]
B=[]

dp=[10**10]*(H+1)
dp[0]=0
for n in range(N):
  a,b=map(int, input().split())
  A.append(a)
  B.append(b)
    
for h in range(1,H+1):
  for n in range(N):
    if h-A[n]>=0:
      dp[h]=min(dp[h],dp[h-A[n]]+B[n])
    else:
      dp[h]=min(dp[h],B[n])
print(dp[H])

Buggy python submission (verdict: Runtime Error):
H,N=map(int, input().split())
import math



MAX=10**4+1
def solve(r,idx):
  if idx==N:
    return MAX
  if r%A[idx][1]==0:
    return (r//A[idx][1])*A[idx][2]
  else:
    return min((r//A[idx][1]+1)*A[idx][2],(r//A[idx][1])*A[idx][2]+solve(r%A[idx][1],idx+1))


A=[]
B=[]
for i in range(N):
  a,b=map(int, input().split())
  A.append([a/b,a,b])
if N==1:
  if H%A[0][1]==0:
  	print((H//A[0][1])*A[0][2])
  else:
 	print((H//A[0][1]+1)*A[0][2])
  return
A=sorted(A)[::-1]

if H%A[0][1]==0:
  print((H//A[0][1])*A[0][2])
else:
  ans=min((H//A[0][1]+1)*A[0][2],(H//A[0][1])*A[0][2]+solve(H%A[0][1],1))
  print(ans)


Fixed submission:
H,N=map(int, input().split())
A=[]
B=[]

dp=[10**10]*(H+1)
dp[0]=0
for n in range(N):
  a,b=map(int, input().split())
  A.append(a)
  B.append(b)
    
for h in range(1,H+1):
  for n in range(N):
    if h-A[n]>=0:
      dp[h]=min(dp[h],dp[h-A[n]]+B[n])
    else:
      dp[h]=min(dp[h],B[n])
print(dp[H])

Buggy python submission (verdict: Runtime Error):
H,N=map(int, input().split())
import math



MAX=10**4+1
def solve(r,idx):
  if idx==N:
    return MAX
  if r%A[idx][1]==0:
    return (r//A[idx][1])*A[idx][2]
  else:
    return min((r//A[idx][1]+1)*A[idx][2],(r//A[idx][1])*A[idx][2]+solve(r%A[idx][1],idx+1))

def main():
  A=[]
  B=[]
  for i in range(N):
    a,b=map(int, input().split())
    A.append([a/b,a,b])
  if N==1:
    if H%A[0][1]==0:
    	print((H//A[0][1])*A[0][2])
  	else:
    	print((H//A[0][1]+1)*A[0][2])
    return
  A=sorted(A)[::-1]

  if H%A[0][1]==0:
    print((H//A[0][1])*A[0][2])
  else:
    ans=min((H//A[0][1]+1)*A[0][2],(H//A[0][1])*A[0][2]+solve(H%A[0][1],1))
    print(ans)

main()

Fixed submission:
H,N=map(int, input().split())
A=[]
B=[]

dp=[10**10]*(H+1)
dp[0]=0
for n in range(N):
  a,b=map(int, input().split())
  A.append(a)
  B.append(b)
    
for h in range(1,H+1):
  for n in range(N):
    if h-A[n]>=0:
      dp[h]=min(dp[h],dp[h-A[n]]+B[n])
    else:
      dp[h]=min(dp[h],B[n])
print(dp[H])

Buggy python submission (verdict: Runtime Error):
H,N=map(int, input().split())
import math

A=[]
B=[]
for i in range(N):
  a,b=map(int, input().split())
  A.append([a/b,a,b])
A=sorted(A)
a=A[0][1]
b=A[0][2]
B.append([a/b,a,b])
new_N=1
for i in range(1,N):
  if a/b !=A[i][1]/A[i][2]:
    a=A[i][1]
    b=A[i][2]
    B.append([a/b,a,b])
    new_N+=1

A=B[::-1]
MAX=10**4+1
N=new_N
def solve(r,idx):
  if idx==N:
    return MAX
  if r%A[idx][1]==0:
    return (r//A[idx][1])*A[idx][2]
  else:
    return min((r//A[idx][1]+1)*A[idx][2],(r//A[idx][1])*A[idx][2]+solve(r%A[idx][1],idx+1))

if H%A[0][1]==0:
  print((H//A[0][1])*A[0][2])
else:
  ans=min((H//A[0][1]+1)*A[0][2],(H//A[0][1])*A[0][2]+solve(H%A[0][1],1))
  print(ans)



Fixed submission:
H,N=map(int, input().split())
A=[]
B=[]

dp=[10**10]*(H+1)
dp[0]=0
for n in range(N):
  a,b=map(int, input().split())
  A.append(a)
  B.append(b)
    
for h in range(1,H+1):
  for n in range(N):
    if h-A[n]>=0:
      dp[h]=min(dp[h],dp[h-A[n]]+B[n])
    else:
      dp[h]=min(dp[h],B[n])
print(dp[H])