Buggy python submission (verdict: Runtime Error):
import sys

import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 10
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    h, n = ns()
    d = [na() for _ in range(n)]

    mat = [INF for _ in range(h + 1)]

    mat[0] = 0
    for i in range(h):
        if mat[i] == INF:
            continue
        for a, b in d:
            if i + a < h + 1:
                mat[i + a] = min(mat[i + a], mat[i] + b)
            else:
                mat[h] = min(mat[h], mat[i] + b)

    print(mat[h])


if __name__ == '__main__':
    main()


Fixed submission:
import sys

# import re
# import math
# import collections
# import decimal
# import bisect
# import itertools
# import fractions
# import functools
# import copy
# import heapq
# import decimal
# import statistics
# import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 10
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    h, n = ns()
    d = [na() for _ in range(n)]

    mat = [INF for _ in range(h + 1)]

    mat[0] = 0
    for i in range(h):
        if mat[i] == INF:
            continue
        for a, b in d:
            if i + a < h + 1:
                mat[i + a] = min(mat[i + a], mat[i] + b)
            else:
                mat[h] = min(mat[h], mat[i] + b)

    print(mat[h])


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 10
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    h, n = ns()
    d = [na() for _ in range(n)]

    mat = [INF for _ in range(h + 1)]

    mat[0] = 0
    for i in range(h):
        if mat[i] == INF:
            continue
        for a, b in d:
            if i + a < h + 1:
                mat[i + a] = min(mat[i + a], mat[i] + b)
            else:
                mat[h] = min(mat[h], mat[i] + b)

    print(mat[h])


if __name__ == '__main__':
    main()


Fixed submission:
import sys

# import re
# import math
# import collections
# import decimal
# import bisect
# import itertools
# import fractions
# import functools
# import copy
# import heapq
# import decimal
# import statistics
# import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 10
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    h, n = ns()
    d = [na() for _ in range(n)]

    mat = [INF for _ in range(h + 1)]

    mat[0] = 0
    for i in range(h):
        if mat[i] == INF:
            continue
        for a, b in d:
            if i + a < h + 1:
                mat[i + a] = min(mat[i + a], mat[i] + b)
            else:
                mat[h] = min(mat[h], mat[i] + b)

    print(mat[h])


if __name__ == '__main__':
    main()