Buggy python submission (verdict: Time Limit Exceeded):
a = list(map(int, input().split()))
HP = a[0]

x = []
for i in range(a[1]):
    x1, y1 = [int(i) for i in input().split()]
    x.append((x1, y1))

max_tup = max(x, key=lambda x: x[0]) #最高攻撃力の呪文を記憶
max_a = max_tup[0] #その攻撃力を記録
#1次元　横：与えるダメージ　中身：最小魔力
dp = [10**10] * (HP + max_a)  #DP表はHP+最高攻撃力
dp[0] = 0

for i in range(1, len(dp)):
    for a, b in x:
        if i >= a:
            dp[i] = min(dp[i],dp[i - a] + b )

print(min(dp[HP:]))

Fixed submission:
a = list(map(int, input().split()))
HP = a[0]

x = []
for i in range(a[1]):
    x1, y1 = [int(i) for i in input().split()]
    x.append((x1, y1))

max_tup = max(x, key=lambda x: x[0])
max_a = max_tup[0]
dp = [0] * (HP + max_a)

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

print(dp[HP])

Buggy python submission (verdict: Time Limit Exceeded):
h,n = map(int,input().split())
li2=[input() for i in range(n)]
ab = []
for i in range(n):
    ab.append( [int(x.strip()) for x in li2[i].split()])

#dp　横を合計攻撃力　中身を最小魔力とする
dp = [100000000] * (h + 10 ** 4 + 1)
#hpを0減らすのに必要な魔力は0
dp[0] = 0

for i in range(h):
    if dp[i] == 100000000:#初期値の場合は更新しない
        continue

    for a, b in ab:#aがアタック bが使用魔力
        t = dp[i] + b #n番目の呪文を使った時、合計の魔力はtとなる
        if t < dp[i + a]: #今入っている魔力が新しい魔力よりも高いとき更新
            dp[i + a] = t
#print(dp)
print(min(dp[h:]))

Fixed submission:
a = list(map(int, input().split()))
HP = a[0]

x = []
for i in range(a[1]):
    x1, y1 = [int(i) for i in input().split()]
    x.append((x1, y1))

max_tup = max(x, key=lambda x: x[0])
max_a = max_tup[0]
dp = [0] * (HP + max_a)

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

print(dp[HP])

Buggy python submission (verdict: Time Limit Exceeded):
h,n = map(int,input().split())
li2=[input() for i in range(n)]
ab = []
w = 10 ** 10
for i in range(n):
    ab.append( [int(x.strip()) for x in li2[i].split()])
    w_sub = (int(h / ab[i][0]) + 1) * ab[i][1]
    if w_sub < w:
        w = w_sub

dp = [[0] * (w+1) for i in range(n+1)]

for i in range(n):
    for j in range(w+1):
        if j < ab[i][1]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i + 1][j] = max(dp[i][j], dp[i+1][j-ab[i][1]]+ab[i][0])

ans = 0
for i in range(w+1):
    if dp[n][i] >= h:
        print(i)
        exit()

Fixed submission:
a = list(map(int, input().split()))
HP = a[0]

x = []
for i in range(a[1]):
    x1, y1 = [int(i) for i in input().split()]
    x.append((x1, y1))

max_tup = max(x, key=lambda x: x[0])
max_a = max_tup[0]
dp = [0] * (HP + max_a)

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

print(dp[HP])

Buggy python submission (verdict: Time Limit Exceeded):
h,n = map(int,input().split())
li2=[input() for i in range(n)]
ab = []
w = 10 ** 10
for i in range(n):
    ab.append( [int(x.strip()) for x in li2[i].split()])
    w_sub = (int(h / ab[i][0]) + 1) * ab[i][1]
    if w_sub < w:
        w = w_sub

dp = [[0] * (w+1) for i in range(n+1)]

for i in range(n):
    for j in range(w+1):
        if j < ab[i][1]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i + 1][j] = max(dp[i][j], dp[i+1][j-ab[i][1]]+ab[i][0])

ans = 0
for i in range(w+1):
    if dp[n][i] >= h:
        print(i)
        exit()

Fixed submission:
a = list(map(int, input().split()))
HP = a[0]

x = []
for i in range(a[1]):
    x1, y1 = [int(i) for i in input().split()]
    x.append((x1, y1))

max_tup = max(x, key=lambda x: x[0])
max_a = max_tup[0]
dp = [0] * (HP + max_a)

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

print(dp[HP])

Buggy python submission (verdict: Runtime Error):
h,n = map(int,input().split())
li2=[input() for i in range(n)]
ab = []
for i in range(n):
    ab.append( [int(x.strip()) for x in li2[i].split()])
w = (int(h/ab[0][0])+1) * ab[0][1]
dp = [[0] * (w+1) for i in range(n+1)]

for i in range(n):
    for j in range(w+1):
        if j < ab[i][1]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i + 1][j] = max(dp[i][j], dp[i+1][j-ab[i][1]]+ab[i][0])

ans = 0
for i in range(w+1):
    if dp[n][i] >= h:
        print(i)
        exit()

Fixed submission:
a = list(map(int, input().split()))
HP = a[0]

x = []
for i in range(a[1]):
    x1, y1 = [int(i) for i in input().split()]
    x.append((x1, y1))

max_tup = max(x, key=lambda x: x[0])
max_a = max_tup[0]
dp = [0] * (HP + max_a)

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

print(dp[HP])

Buggy python submission (verdict: Time Limit Exceeded):
h,n = map(int,input().split())
li2=[input() for i in range(n)]
ab = []
for i in range(n):
    ab.append( [int(x.strip()) for x in li2[i].split()])
w = (int(h/ab[0][0])+1) * ab[0][1]
dp = [[0] * (w+1) for i in range(n+1)]

for i in range(n):
    for j in range(w+1):
        if j < ab[i][1]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i + 1][j] = max(dp[i][j], dp[i+1][j-ab[i][1]]+ab[i][0])

ans = 0
for i in range(w+1):
    if dp[n][i] >= h:
        print(i)
        exit()

Fixed submission:
a = list(map(int, input().split()))
HP = a[0]

x = []
for i in range(a[1]):
    x1, y1 = [int(i) for i in input().split()]
    x.append((x1, y1))

max_tup = max(x, key=lambda x: x[0])
max_a = max_tup[0]
dp = [0] * (HP + max_a)

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

print(dp[HP])