Buggy python submission (verdict: Time Limit Exceeded):
h, n = (int(x) for x in input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
dp = [0] * (h + 1)
for i in range(1, h + 1):
    dp[i] = min(b if i - a < 0 else dp[i - a] + b for a, b in ab)
print(dp[h])

Fixed submission:
h, n = (int(x) for x in input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
max_a = max(a for a, _ in ab)
dp = [0] * (h + max_a)
for i in range(1, h + 1):
    dp[i] = min(dp[i - a] + b for a, b in ab)
print(dp[h])

Buggy python submission (verdict: Runtime Error):
h, n = (int(x) for x in input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
dp = [0] * (h + 1)
for i in range(1, h + 1):
    dp[i] = min(dp[i - a] + b for a, b in ab)
print(dp[h])

Fixed submission:
h, n = (int(x) for x in input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
max_a = max(a for a, _ in ab)
dp = [0] * (h + max_a)
for i in range(1, h + 1):
    dp[i] = min(dp[i - a] + b for a, b in ab)
print(dp[h])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
def main():
    h, n = (int(x) for x in input().split())
    ab = []
    for _ in range(n):
        a, b = (int(x) for x in input().split())
        ab.append([a, b])
    dp = [float('inf')] * (h)
    for a, b in ab:
        for i in range(h):
            if i < a:
                dp[i] = min(dp[i], b)
            else:
                dp[i] = min(dp[i], dp[i - a] + b)
    print(dp[h - 1])
if __name__=='__main__':
    main()

Fixed submission:
h, n = (int(x) for x in input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
max_a = max(a for a, _ in ab)
dp = [0] * (h + max_a)
for i in range(1, h + 1):
    dp[i] = min(dp[i - a] + b for a, b in ab)
print(dp[h])

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    h, n = (int(x) for x in input().split())
    ab = []
    for _ in range(n):
        a, b = (int(x) for x in input().split())
        ab.append([a, b])
    dp = [float('inf')] * (h)
    for a, b in ab:
        for i in range(h):
            if i < a:
                dp[i] = min(dp[i], b)
            else:
                dp[i] = min(dp[i], dp[i - a] + b)
    print(dp[h - 1])
if __name__=='__main__':
    main()

Fixed submission:
h, n = (int(x) for x in input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
max_a = max(a for a, _ in ab)
dp = [0] * (h + max_a)
for i in range(1, h + 1):
    dp[i] = min(dp[i - a] + b for a, b in ab)
print(dp[h])

Buggy python submission (verdict: Time Limit Exceeded):
h, n = (int(x) for x in input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
dp = [float('inf')] * (h)
for a, b in ab:
    for i in range(h):
        if i < a:
            if dp[i] > b:
                dp[i] = b
        else:
            if dp[i] > dp[i - a] + b:
                dp[i] =  dp[i - a] + b
print(dp[h - 1])

Fixed submission:
h, n = (int(x) for x in input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
max_a = max(a for a, _ in ab)
dp = [0] * (h + max_a)
for i in range(1, h + 1):
    dp[i] = min(dp[i - a] + b for a, b in ab)
print(dp[h])

Buggy python submission (verdict: Time Limit Exceeded):
h, n = (int(x) for x in input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
dp = [float('inf')] * (h)
for a, b in ab:
    for i in range(h):
        if i < a:
            dp[i] = min(dp[i], b)
        else:
            dp[i] = min(dp[i], dp[i - a] + b)
print(dp[h - 1])

Fixed submission:
h, n = (int(x) for x in input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
max_a = max(a for a, _ in ab)
dp = [0] * (h + max_a)
for i in range(1, h + 1):
    dp[i] = min(dp[i - a] + b for a, b in ab)
print(dp[h])

Buggy python submission (verdict: Time Limit Exceeded):
h, n = (int(x) for x in input().split())
w = []
v = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    w.append(a)
    v.append(b)
dp = [float('inf')] * (h)
for i in range(n):
    for j in range(h):
        if j < w[i]:
            dp[j] = min(dp[j], v[i])
        else:
            dp[j] = min(dp[j], dp[j - w[i]] + v[i])
print(dp[h - 1])

Fixed submission:
h, n = (int(x) for x in input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
max_a = max(a for a, _ in ab)
dp = [0] * (h + max_a)
for i in range(1, h + 1):
    dp[i] = min(dp[i - a] + b for a, b in ab)
print(dp[h])

Buggy python submission (verdict: Time Limit Exceeded):
h, n = (int(x) for x in input().split())
w = []
v = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    w.append(a)
    v.append(b)
dp = [[float('inf')] * (h) for _ in range(n + 1)]
for i in range(n):
    for j in range(h):
        if j < w[i]:
            dp[i + 1][j] = min(dp[i][j], v[i])
        else:
            dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - w[i]] + v[i])
print(dp[n][h - 1])

Fixed submission:
h, n = (int(x) for x in input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
max_a = max(a for a, _ in ab)
dp = [0] * (h + max_a)
for i in range(1, h + 1):
    dp[i] = min(dp[i - a] + b for a, b in ab)
print(dp[h])