Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
from heapq import heappop, heappush
#from collections import defaultdict
# import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
#import numpy as np
# from copy import deepcopy
#from collections import deque
#import numba

def run():
    H, N = map(int, sysread().split())
    AB = list(map(int, read().split()))
    A = AB[::2]
    B = AB[1::2]

    INF = float('inf')
    dp = [[INF] * (2*H+2) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(2*H+2):
            tmp = j - A[i]
            if tmp >= 0:
                dp[i+1][j] = min([dp[i][j], dp[i+1][tmp] + B[i]])
            elif j == H and tmp < 0:
                dp[i + 1][H] = min(dp[i][H], dp[i + 1][0] + B[i])
            else:
                dp[i+1][j] = dp[i][j]
    ret = min(dp[N][H:])
    print(ret)



if __name__ == "__main__":
    run()

Fixed submission:
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
from heapq import heappop, heappush
#from collections import defaultdict
# import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
#import numpy as np
# from copy import deepcopy
#from collections import deque
#import numba

def run():
    H, N = map(int, sysread().split())
    AB = list(map(int, read().split()))
    A = AB[::2]
    B = AB[1::2]
    Amax = max(A)

    INF = float('inf')
    dp = [[INF] * (H+Amax+1) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(H+Amax+1):
            tmp = j - A[i]
            if tmp >= 0:
                dp[i+1][j] = min([dp[i][j], dp[i+1][tmp] + B[i]])
            elif j == H and tmp < 0:
                dp[i + 1][H] = min(dp[i][H], dp[i + 1][0] + B[i])
            else:
                dp[i+1][j] = dp[i][j]
    ret = min(dp[N][H:])
    print(ret)



if __name__ == "__main__":
    run()

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
from heapq import heappop, heappush
#from collections import defaultdict
# import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
#import numpy as np
# from copy import deepcopy
#from collections import deque
#import numba

def run():
    H, N = map(int, sysread().split())
    AB = []
    for i in range(N):
        a,b = map(int, sysread().split())
        AB.append((a,b))

    INF = float('inf')
    dp = [[INF] * (2*H+2) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(2*H+2):
            tmp = j - AB[i][0]
            if tmp >= 0:
                dp[i+1][j] = min([dp[i][j], dp[i+1][tmp] + AB[i][1]])
            elif j == H and tmp < 0:
                dp[i + 1][H] = min(dp[i][H], dp[i + 1][0] + AB[i][1])
            else:
                dp[i+1][j] = dp[i][j]
    ret = min(dp[N][H:])
    print(ret)



if __name__ == "__main__":
    run()

Fixed submission:
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
from heapq import heappop, heappush
#from collections import defaultdict
# import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
#import numpy as np
# from copy import deepcopy
#from collections import deque
#import numba

def run():
    H, N = map(int, sysread().split())
    AB = list(map(int, read().split()))
    A = AB[::2]
    B = AB[1::2]
    Amax = max(A)

    INF = float('inf')
    dp = [[INF] * (H+Amax+1) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(H+Amax+1):
            tmp = j - A[i]
            if tmp >= 0:
                dp[i+1][j] = min([dp[i][j], dp[i+1][tmp] + B[i]])
            elif j == H and tmp < 0:
                dp[i + 1][H] = min(dp[i][H], dp[i + 1][0] + B[i])
            else:
                dp[i+1][j] = dp[i][j]
    ret = min(dp[N][H:])
    print(ret)



if __name__ == "__main__":
    run()

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
from heapq import heappop, heappush
#from collections import defaultdict
# import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
#import numpy as np
# from copy import deepcopy
#from collections import deque
#import numba

def run():
    H, N = map(int, sysread().split())
    AB = []
    for i in range(N):
        a,b = map(int, sysread().split())
        AB.append((a,b))

    INF = float('inf')
    dp = [[INF] * (2*H+2) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(2*H+2):
            tmp = j - AB[i][0]
            if tmp >= 0:
                dp[i+1][j] = min([dp[i][j], dp[i+1][tmp] + AB[i][1]])
            elif j == H and tmp < 0:
                dp[i + 1][H] = min(dp[i][H], dp[i + 1][0] + AB[i][1])
            else:
                dp[i+1][j] = dp[i][j]
    ret = min(dp[N][H:])
    print(ret)



if __name__ == "__main__":
    run()

Fixed submission:
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
from heapq import heappop, heappush
#from collections import defaultdict
# import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
#import numpy as np
# from copy import deepcopy
#from collections import deque
#import numba

def run():
    H, N = map(int, sysread().split())
    AB = list(map(int, read().split()))
    A = AB[::2]
    B = AB[1::2]
    Amax = max(A)

    INF = float('inf')
    dp = [[INF] * (H+Amax+1) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(H+Amax+1):
            tmp = j - A[i]
            if tmp >= 0:
                dp[i+1][j] = min([dp[i][j], dp[i+1][tmp] + B[i]])
            elif j == H and tmp < 0:
                dp[i + 1][H] = min(dp[i][H], dp[i + 1][0] + B[i])
            else:
                dp[i+1][j] = dp[i][j]
    ret = min(dp[N][H:])
    print(ret)



if __name__ == "__main__":
    run()

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
#from heapq import heappop, heappush
#from collections import defaultdict
# import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
#import numpy as np
# from copy import deepcopy
#from collections import deque
#import numba

def run():
    H, N = map(int, sysread().split())
    AB = list(map(int, read().split()))
    A = [0] + AB[0::2]
    B = [0] + AB[1::2]

    INF = float('inf')
    dp = [[INF] * (H+1) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(0, N):
        for v in range(H+1):
            dp[i+1][v] = min(dp[i][v], dp[i+1][v])
            do = True
            pre_v = v
            while do:
                next_v = pre_v + A[i+1]
                if next_v >= H:
                    next_v = H
                    do = False
                dp[i+1][next_v] = min(dp[i+1][next_v], dp[i+1][pre_v] + B[i+1])
                pre_v = next_v
    print(dp[N][H])

if __name__ == "__main__":
    run()

Fixed submission:
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
from heapq import heappop, heappush
#from collections import defaultdict
# import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
#import numpy as np
# from copy import deepcopy
#from collections import deque
#import numba

def run():
    H, N = map(int, sysread().split())
    AB = list(map(int, read().split()))
    A = AB[::2]
    B = AB[1::2]
    Amax = max(A)

    INF = float('inf')
    dp = [[INF] * (H+Amax+1) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(H+Amax+1):
            tmp = j - A[i]
            if tmp >= 0:
                dp[i+1][j] = min([dp[i][j], dp[i+1][tmp] + B[i]])
            elif j == H and tmp < 0:
                dp[i + 1][H] = min(dp[i][H], dp[i + 1][0] + B[i])
            else:
                dp[i+1][j] = dp[i][j]
    ret = min(dp[N][H:])
    print(ret)



if __name__ == "__main__":
    run()

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
#from heapq import heappop, heappush
#from collections import defaultdict
# import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
#import numpy as np
# from copy import deepcopy
#from collections import deque
#import numba

def run():
    H, N = map(int, sysread().split())
    AB = list(map(int, read().split()))
    A = [0] + AB[0::2]
    B = [0] + AB[1::2]

    INF = float('inf')
    dp = [[INF] * (H+1) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(0, N):
        for v in range(H+1):
            dp[i+1][v] = min(dp[i][v], dp[i+1][v])
            do = True
            pre_v = v
            while do:
                next_v = pre_v + A[i+1]
                if next_v >= H:
                    next_v = H
                    do = False
                dp[i+1][next_v] = min(dp[i+1][next_v], dp[i+1][pre_v] + B[i+1])
                pre_v = next_v
    print(dp[N][H])

if __name__ == "__main__":
    run()

Fixed submission:
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
from heapq import heappop, heappush
#from collections import defaultdict
# import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
#import numpy as np
# from copy import deepcopy
#from collections import deque
#import numba

def run():
    H, N = map(int, sysread().split())
    AB = list(map(int, read().split()))
    A = AB[::2]
    B = AB[1::2]
    Amax = max(A)

    INF = float('inf')
    dp = [[INF] * (H+Amax+1) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(H+Amax+1):
            tmp = j - A[i]
            if tmp >= 0:
                dp[i+1][j] = min([dp[i][j], dp[i+1][tmp] + B[i]])
            elif j == H and tmp < 0:
                dp[i + 1][H] = min(dp[i][H], dp[i + 1][0] + B[i])
            else:
                dp[i+1][j] = dp[i][j]
    ret = min(dp[N][H:])
    print(ret)



if __name__ == "__main__":
    run()