Buggy python submission (verdict: Runtime Error):
H, N = map(int, input().split(' '))
magic = [[0 for _ in range(3)] for j in range(N)]
for i in range(N):
  temp_a, temp_b = map(int, input().split())
  magic[i][0] = temp_a
  magic[i][1] = temp_b

dp = [float('inf')] * (H + 1)
dp[0] = 0

start = float('inf')
minimum = float('inf')
for i in range(N):
  start = min(start, magic[i][0])
  minimum = min(minimum, magic[i][1])

for i in range(1, start + 1):
  dp[i] = minimum

for i in range(start + 1, H + 1):
  for j in range(N):
    if i >= magic[j][0]:
      dp[i] = min(dp[i - magic[j][0]] + magic[j][1], dp[i])
    else:
      dp[i] = min(magic[j][1], dp[i])

print(dp[H])

Fixed submission:
H, N = map(int, input().split(' '))
magic = [[0 for _ in range(3)] for j in range(N)]
for i in range(N):
  temp_a, temp_b = map(int, input().split())
  magic[i][0] = temp_a
  magic[i][1] = temp_b

dp = [float('inf')] * (H + 1)
dp[0] = 0

for i in range(1, H + 1):
  for j in range(N):
    if i >= magic[j][0]:
      dp[i] = min(dp[i - magic[j][0]] + magic[j][1], dp[i])
    else:
      dp[i] = min(magic[j][1], dp[i])

print(dp[H])

Buggy python submission (verdict: Runtime Error):
H, N = map(int, input().split(' '))
magic = [[0 for _ in range(3)] for j in range(N)]
for i in range(N):
  temp_a, temp_b = map(int, input().split())
  magic[i][0] = temp_a
  magic[i][1] = temp_b
#   magic[i][2] = temp_a / temp_b

dp = [float('inf')] * (H + 1)
dp[0] = 0

start = float('inf')
minimum = float('inf')
for i in range(N):
  start = min(start, magic[i][0])
  minimum = min(minimum, magic[i][1])

for i in range(1, start + 1):
  dp[i] = minimum

for i in range(1, H + 1):
  for j in range(N):
    if i >= magic[j][0]:
      dp[i] = min(dp[i - magic[j][0]] + magic[j][1], dp[i])
    else:
      dp[i] = min(magic[j][1], dp[i])

print(dp[H])

Fixed submission:
H, N = map(int, input().split(' '))
magic = [[0 for _ in range(3)] for j in range(N)]
for i in range(N):
  temp_a, temp_b = map(int, input().split())
  magic[i][0] = temp_a
  magic[i][1] = temp_b

dp = [float('inf')] * (H + 1)
dp[0] = 0

for i in range(1, H + 1):
  for j in range(N):
    if i >= magic[j][0]:
      dp[i] = min(dp[i - magic[j][0]] + magic[j][1], dp[i])
    else:
      dp[i] = min(magic[j][1], dp[i])

print(dp[H])

Buggy python submission (verdict: Time Limit Exceeded):
H, N = map(int, input().split(' '))
magic = [[0 for _ in range(3)] for j in range(N)]
for i in range(N):
  temp_a, temp_b = map(int, input().split())
  magic[i][0] = temp_a
  magic[i][1] = temp_b

dp = [float('inf')] * (H + 1)
dp[0] = 0

for i in range(1, H + 1):
  for j in range(N):
    if i >= magic[j][0]:
      dp[i] = min(dp[i - magic[j][0]] + magic[j][1], dp[i])
    else:
      dp[i] = min(magic[j][1], dp[i])

print(dp[H])

Fixed submission:
H, N = map(int, input().split(' '))
magic = [[0 for _ in range(3)] for j in range(N)]
for i in range(N):
  temp_a, temp_b = map(int, input().split())
  magic[i][0] = temp_a
  magic[i][1] = temp_b

dp = [float('inf')] * (H + 1)
dp[0] = 0

for i in range(1, H + 1):
  for j in range(N):
    if i >= magic[j][0]:
      dp[i] = min(dp[i - magic[j][0]] + magic[j][1], dp[i])
    else:
      dp[i] = min(magic[j][1], dp[i])

print(dp[H])

Buggy python submission (verdict: Time Limit Exceeded):
H, N = map(int, input().split(' '))
magic = [[0 for _ in range(3)] for j in range(N)]
total_cost = 0
for i in range(N):
  temp_a, temp_b = map(int, input().split())
  magic[i][0] = temp_a
  magic[i][1] = temp_b
  magic[i][2] = temp_a / temp_b

hp = H
dp = [float('inf')] * (H + 1)
dp[0] = 0
for i in range(1, H + 1):
  for j in range(N):
    if i >= magic[j][0]:
      dp[i] = min(dp[i - magic[j][0]] + magic[j][1], dp[i])
    else:
      dp[i] = min(magic[j][1], dp[i])

print(dp[H])

Fixed submission:
H, N = map(int, input().split(' '))
magic = [[0 for _ in range(3)] for j in range(N)]
for i in range(N):
  temp_a, temp_b = map(int, input().split())
  magic[i][0] = temp_a
  magic[i][1] = temp_b

dp = [float('inf')] * (H + 1)
dp[0] = 0

for i in range(1, H + 1):
  for j in range(N):
    if i >= magic[j][0]:
      dp[i] = min(dp[i - magic[j][0]] + magic[j][1], dp[i])
    else:
      dp[i] = min(magic[j][1], dp[i])

print(dp[H])