Buggy python submission (verdict: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <vector>

#define REP(i,n) for(int i=0;i<n;i++)
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


using namespace std;
using ll=long long;
ll mod = 1e9 + 7;

//int dp[1e5];
//memset(dp, BMAX*HMAX, sizeof(dp));
  
int main() {
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    for(int i=0;i<N;i++){
        cin >> A[i] >> B[i];
    }
    vector<ll> dp(H+1, 1e9);
    dp[0] = 0;
    for(int i=0;i<H;i++){
        for(int j=0;j<N;j++){
            chmin(dp[min(i+A[j], H)], dp[i]+B[j]);
        }
    }
    cout << dp[H] << endl;
	return 0;
}


Fixed submission:
import sys

input = sys.stdin.readline
H, N = map(int, input().split())
magic = [list(map(int, input().split())) for _ in range(N)]

max_damage = max(damage for damage, cost in magic)
dp = [0] * (H + max_damage)

for x in range(1, H + max_damage):
    dp[x] = min(dp[x - damage] + cost for damage, cost in magic)

ans = min(dp[H:])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, N = map(int, input().split())
A, B = [], []
for _ in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)

dp = [1e9]*(H+max(A))
dp[0] = 0
for h in range(H):
  for n in range(N):
    dp[h+A[n]] = min(dp[h+A[n]], dp[h]+B[n])
print(min(dp[H:]))

Fixed submission:
import sys

input = sys.stdin.readline
H, N = map(int, input().split())
magic = [list(map(int, input().split())) for _ in range(N)]

max_damage = max(damage for damage, cost in magic)
dp = [0] * (H + max_damage)

for x in range(1, H + max_damage):
    dp[x] = min(dp[x - damage] + cost for damage, cost in magic)

ans = min(dp[H:])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, N = list(map(int, input().split()))
AB = [[None,None]]
for i in range(N):
  AB.append(list(map(int, input().split())))

dp = [int(1e8) for i in range(H+1)]
dp[0] = 0

for h in range(1,H+1):
  cand = [dp[0] + AB[n][1] if h - AB[n][0] < 0 else dp[h-AB[n][0]] + AB[n][1]for n in range(1,N+1) ]
  dp[h] = min(cand)
print(dp[H])

Fixed submission:
import sys

input = sys.stdin.readline
H, N = map(int, input().split())
magic = [list(map(int, input().split())) for _ in range(N)]

max_damage = max(damage for damage, cost in magic)
dp = [0] * (H + max_damage)

for x in range(1, H + max_damage):
    dp[x] = min(dp[x - damage] + cost for damage, cost in magic)

ans = min(dp[H:])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, N = list(map(int, input().split()))
AB = [[None,None]]
for i in range(N):
  AB.append(list(map(int, input().split())))

dp = [int(1e8) for i in range(H+1)]
dp[0] = 0

for h in range(1,H+1):
  cand = []
  for n in range(1,N+1):
    if h - AB[n][0] < 0:
        cand.append(dp[0] + AB[n][1])
    else:
        cand.append(dp[h-AB[n][0]] + AB[n][1])
  dp[h] = min(cand)
print(dp[H])

Fixed submission:
import sys

input = sys.stdin.readline
H, N = map(int, input().split())
magic = [list(map(int, input().split())) for _ in range(N)]

max_damage = max(damage for damage, cost in magic)
dp = [0] * (H + max_damage)

for x in range(1, H + max_damage):
    dp[x] = min(dp[x - damage] + cost for damage, cost in magic)

ans = min(dp[H:])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, N = list(map(int, input().split()))
AB = [[None,None]]
for i in range(N):
  AB.append(list(map(int, input().split())))

dp = [[int(1e8) for i in range(H+1)] for j in range(N+1)] 
for n in range(N+1):
  dp[n][0] = 0

for n in range(1,N+1):
  for h in range(1,H+1):
    ionly_n = int(h/AB[n][0]) + 1
    cand = [dp[n-1][h-i_n*AB[n][0]] + AB[n][1] * i_n for i_n in range(ionly_n)] + [AB[n][1] * ionly_n]
    dp[n][h] = min(cand)
#print(dp)
print(dp[N][H])

Fixed submission:
import sys

input = sys.stdin.readline
H, N = map(int, input().split())
magic = [list(map(int, input().split())) for _ in range(N)]

max_damage = max(damage for damage, cost in magic)
dp = [0] * (H + max_damage)

for x in range(1, H + max_damage):
    dp[x] = min(dp[x - damage] + cost for damage, cost in magic)

ans = min(dp[H:])

print(ans)