Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
# 整数の入力
#a = int(input())
# スペース区切りの整数の入力
#b, c = map(int, input().split())
# 文字列の入力
#s = input()
# 出力
#print("{} {}".format(a+b+c, s))

import numpy as np

h, n = map(int, input().split())

ab=[[0]*2 for i in range(n)]
maxa=0

for i in range(0,n):
  ab[i][0], ab[i][1] = map(int, input().split())

sab=sorted(ab)
maxl = 2*10**8
maxa=sab[len(sab)-1][0]
maxi = h+sab[len(sab)-1][0]
ans = [maxl]*maxi
ans[0] = 0

for i in range(1,maxi):
  for j in range(0,n):
    if i < sab[j][0]:
      break
    ans[i] = min(ans[i-sab[j][0]]+sab[j][1], ans[i])

#print(sab)
#print(ans)
print(min(ans[h:]))

Fixed submission:
# -*- coding: utf-8 -*-
# 整数の入力
#a = int(input())
# スペース区切りの整数の入力
#b, c = map(int, input().split())
# 文字列の入力
#s = input()
# 出力
#print("{} {}".format(a+b+c, s))

import numpy as np

h, n = map(int, input().split())
inf=2*10**9
a = np.full(n,inf, int)
b = np.full(n,inf, int)
for i in range(0, n):
  a[i], b[i] = map(int, input().split())

dp=np.full(10001,0,int)
dp[0]=0

for i in range(1,h+1):
  dp[i]=(dp[i-a]+b).min()

print(dp[h])

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
# 整数の入力
#a = int(input())
# スペース区切りの整数の入力
#b, c = map(int, input().split())
# 文字列の入力
#s = input()
# 出力
#print("{} {}".format(a+b+c, s))

import numpy as np

h, n = map(int, input().split())

ab=[[0]*2 for i in range(n)]
maxa=0

for i in range(0,n):
  ab[i][0], ab[i][1] = map(int, input().split())
  if maxa<ab[i][0]:
    maxa=ab[i][0]

sab=sorted(ab,key=lambda x:x[0]*10**5-x[1])

ans=[0]*(h+maxa)
maxl=2*10**8

for i in range(1,h+maxa):
  ans[i]=maxl
  for j in range(0,n):
    if i<sab[j][0]:
      break
    ans[i] = min(ans[i], ans[i-sab[j][0]]+sab[j][1])
print(min(ans[h:h+maxa]))


Fixed submission:
# -*- coding: utf-8 -*-
# 整数の入力
#a = int(input())
# スペース区切りの整数の入力
#b, c = map(int, input().split())
# 文字列の入力
#s = input()
# 出力
#print("{} {}".format(a+b+c, s))

import numpy as np

h, n = map(int, input().split())
inf=2*10**9
a = np.full(n,inf, int)
b = np.full(n,inf, int)
for i in range(0, n):
  a[i], b[i] = map(int, input().split())

dp=np.full(10001,0,int)
dp[0]=0

for i in range(1,h+1):
  dp[i]=(dp[i-a]+b).min()

print(dp[h])

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 整数の入力
#a = int(input())
# スペース区切りの整数の入力
#b, c = map(int, input().split())
# 文字列の入力
#s = input()
# 出力
#print("{} {}".format(a+b+c, s))

import numpy as np

h, n = map(int, input().split())

ab=[[0]*2 for i in range(n)]
maxa=0

for i in range(0,n):
  ab[i][0], ab[i][1] = map(int, input().split())
  if maxa<ab[i][0]:
    maxa=ab[i][0]

sab=sorted(ab,key=lambda x:x[0]*10**5-x[1])

ans=[0]*(h+maxa)
maxl=2*10**8

for i in range(1,h+maxa):
  ans[i]=maxl
  for j in range(0,n):
    if i<sab[j][0]:
      break
    if ans[i] > (ans[i-sab[j][0]]+sab[j][1]):
      ans[i] = ans[i-sab[j][0]]+sab[j][1]

print(min(ans[h:h+maxa-1]))


Fixed submission:
# -*- coding: utf-8 -*-
# 整数の入力
#a = int(input())
# スペース区切りの整数の入力
#b, c = map(int, input().split())
# 文字列の入力
#s = input()
# 出力
#print("{} {}".format(a+b+c, s))

import numpy as np

h, n = map(int, input().split())
inf=2*10**9
a = np.full(n,inf, int)
b = np.full(n,inf, int)
for i in range(0, n):
  a[i], b[i] = map(int, input().split())

dp=np.full(10001,0,int)
dp[0]=0

for i in range(1,h+1):
  dp[i]=(dp[i-a]+b).min()

print(dp[h])

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 整数の入力
#a = int(input())
# スペース区切りの整数の入力
#b, c = map(int, input().split())
# 文字列の入力
#s = input()
# 出力
#print("{} {}".format(a+b+c, s))

import numpy as np

h, n = map(int, input().split())

ab=[[0]*2 for i in range(n)]
maxa=0

for i in range(0,n):
  ab[i][0], ab[i][1] = map(int, input().split())
  if maxa<ab[i][0]:
    maxa=ab[i][0]

sab=sorted(ab,key=lambda x:-x[0]*10**5+x[1])

ans=[0]*(h+maxa)
maxl=2*10**8

for i in range(1,h+maxa):
  ans[i]=maxl
  for j in range(0,n):
    if (i-sab[j][0]) >= 0:
      if ans[i] > (ans[i-sab[j][0]]+sab[j][1]):
        ans[i] = ans[i-sab[j][0]]+sab[j][1]

print(min(ans[h:h+maxa-1]))


Fixed submission:
# -*- coding: utf-8 -*-
# 整数の入力
#a = int(input())
# スペース区切りの整数の入力
#b, c = map(int, input().split())
# 文字列の入力
#s = input()
# 出力
#print("{} {}".format(a+b+c, s))

import numpy as np

h, n = map(int, input().split())
inf=2*10**9
a = np.full(n,inf, int)
b = np.full(n,inf, int)
for i in range(0, n):
  a[i], b[i] = map(int, input().split())

dp=np.full(10001,0,int)
dp[0]=0

for i in range(1,h+1):
  dp[i]=(dp[i-a]+b).min()

print(dp[h])