Buggy python submission (verdict: Time Limit Exceeded):
# 1-index
from sys import stdin
H, N = [int(x) for x in stdin.readline().rstrip().split()]

data = [0]*N

for i in range(N):
    A, B = [int(x) for x in stdin.readline().rstrip().split()]
    data[i] = (A, B)
dp = [10**9]*(H+1)
dp[0] = 0

for h in range(0,H+1):
    for a,b in data:
        if h+a >= H:
            dp[H] = min(dp[h]+b,dp[H])
        else:
            dp[h+a] = min(dp[h]+b,dp[h+a])
print(dp[H])

Fixed submission:
# 1-index
from sys import stdin
H, N = [int(x) for x in stdin.readline().rstrip().split()]

data = [0]*N

for i in range(N):
    A, B = [int(x) for x in stdin.readline().rstrip().split()]
    data[i] = (A, B)
dp = [10**9]*(H+1)
dp[0] = 0

for h in range(0,H+1):
    for a,b in data:
        if h+a >= H:
            dp[H] = min(dp[h]+b,dp[H])
        else:
            dp[h+a] = min(dp[h]+b,dp[h+a])
print(dp[H])

Buggy python submission (verdict: Runtime Error):
from sys import stdin
H,N = [int(x) for x in stdin.readline().rstrip().split()]
data = []
ans = 10**9
for i in range(N):
    A,B = [int(x) for x in stdin.readline().rstrip().split()]
    C = A / B
    if A >= H:
        ans = min(ans,B)
    data.append((C,A,B))


dp = [10**9]*(H+1)

c,a,b = sorted(data)[::-1][0]

cnt = 0
for i in range(1,H+1):
    cnt += 1
    if cnt*a >= H:
        dp[-1] = (b*cnt)
        break
    else:
        dp[cnt*a] = (b*cnt)
        

tmp = 10**9
for j in range(H,-1,-1):
    tmp = min(dp[j],tmp)
    dp[j] = tmp

for c,a,b in data:
    dp[-1] = min(dp[-a] + b ,dp[-1])
    
for c,a,b in data:
    dp[-1] = min(dp[-2*a] + (2*b) ,dp[-1])

tmp = 10**9
for j in range(H,-1,-1):
    tmp = min(dp[j],tmp)
    dp[j] = tmp
    
print(min(ans,dp[-1]))

Fixed submission:
# 1-index
from sys import stdin
H, N = [int(x) for x in stdin.readline().rstrip().split()]

data = [0]*N

for i in range(N):
    A, B = [int(x) for x in stdin.readline().rstrip().split()]
    data[i] = (A, B)
dp = [10**9]*(H+1)
dp[0] = 0

for h in range(0,H+1):
    for a,b in data:
        if h+a >= H:
            dp[H] = min(dp[h]+b,dp[H])
        else:
            dp[h+a] = min(dp[h]+b,dp[h+a])
print(dp[H])

Buggy python submission (verdict: Runtime Error):
from sys import stdin
H,N = [int(x) for x in stdin.readline().rstrip().split()]
data = []
ans = 10**9
for i in range(N):
    A,B = [int(x) for x in stdin.readline().rstrip().split()]
    C = A / B
    if A >= H:
        ans = min(ans,B)
    data.append((C,A,B))


dp = [10**9]*(H+1)

c,a,b = sorted(data)[::-1][0]

cnt = 0
for i in range(1,H+1):
    cnt += 1
    if cnt*a >= H:
        dp[-1] = (b*cnt)
        break
    else:
        dp[cnt*a] = (b*cnt)
        

tmp = 10**9
for j in range(H,-1,-1):
    tmp = min(dp[j],tmp)
    dp[j] = tmp

for c,a,b in data:
    dp[-1] = min(dp[-a] + b ,dp[-1])

print(min(ans,dp[-1]))

Fixed submission:
# 1-index
from sys import stdin
H, N = [int(x) for x in stdin.readline().rstrip().split()]

data = [0]*N

for i in range(N):
    A, B = [int(x) for x in stdin.readline().rstrip().split()]
    data[i] = (A, B)
dp = [10**9]*(H+1)
dp[0] = 0

for h in range(0,H+1):
    for a,b in data:
        if h+a >= H:
            dp[H] = min(dp[h]+b,dp[H])
        else:
            dp[h+a] = min(dp[h]+b,dp[h+a])
print(dp[H])