Buggy python submission (verdict: Runtime Error):
H,N = map(int,input().split())
AB = [list(map(int, input().split())) for i in range(N)]

M = 1

dp = [0]*(H+M)

for i in range(1,H+M):
    dp[i] = min(dp[i-a]+b for a,b in AB)
    
print(min(dp[H:]))

Fixed submission:
H,N = map(int,input().split())
AB = [list(map(int, input().split())) for i in range(N)]

M = max(a for a,b in AB)

dp = [0]*(H+M)

for i in range(1,H+M):
    dp[i] = min(dp[i-a]+b for a,b in AB)
    
print(min(dp[H:]))

Buggy python submission (verdict: Runtime Error):
H,N = map(int,input().split())
AB = [list(map(int, input().split())) for i in range(N)]

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 = map(int,input().split())
AB = [list(map(int, input().split())) for i in range(N)]

M = max(a for a,b in AB)

dp = [0]*(H+M)

for i in range(1,H+M):
    dp[i] = min(dp[i-a]+b for a,b in AB)
    
print(min(dp[H:]))

Buggy python submission (verdict: Time Limit Exceeded):
H,N = map(int,input().split())
AB = [list(map(int, input().split())) for i in range(N)]

dp = [0]*(H+1)

for i in range(1,H+1):
    dp[i] = min(dp[max(0,i-a)]+b for a,b in AB)
    
print(dp[H])

Fixed submission:
H,N = map(int,input().split())
AB = [list(map(int, input().split())) for i in range(N)]

M = max(a for a,b in AB)

dp = [0]*(H+M)

for i in range(1,H+M):
    dp[i] = min(dp[i-a]+b for a,b in AB)
    
print(min(dp[H:]))

Buggy python submission (verdict: Time Limit Exceeded):
H,N = map(int,input().split())

AB = []

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

dp = [0]*(H+1)
dp[0] = 0

for i in range(1,H+1):
    dp[i] = min(dp[max(0,i-a)]+b for a,b in AB)
    
print(dp[H])

Fixed submission:
H,N = map(int,input().split())
AB = [list(map(int, input().split())) for i in range(N)]

M = max(a for a,b in AB)

dp = [0]*(H+M)

for i in range(1,H+M):
    dp[i] = min(dp[i-a]+b for a,b in AB)
    
print(min(dp[H:]))

Buggy python submission (verdict: Runtime Error):
H,N = map(int,input().split())

AB = []

for i in range(N):
    a,b = map(int,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 = map(int,input().split())
AB = [list(map(int, input().split())) for i in range(N)]

M = max(a for a,b in AB)

dp = [0]*(H+M)

for i in range(1,H+M):
    dp[i] = min(dp[i-a]+b for a,b in AB)
    
print(min(dp[H:]))

Buggy python submission (verdict: Runtime Error):
H,N = map(int,input().split())

AB = []

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

dp = [1e9]*(H+3)

for i in range(H+1):
    dp[i] = min(dp[i-a]+b for a,b in AB)
    
print(min(dp[H-1:]))

Fixed submission:
H,N = map(int,input().split())
AB = [list(map(int, input().split())) for i in range(N)]

M = max(a for a,b in AB)

dp = [0]*(H+M)

for i in range(1,H+M):
    dp[i] = min(dp[i-a]+b for a,b in AB)
    
print(min(dp[H:]))

Buggy python submission (verdict: Runtime Error):
H,N = map(int,input().split())

AB = []

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

dp = [0]*(H+1)

for i in range(H+1):
    dp[i] = min(dp[i-a]+b for a,b in AB)
    
print(min(dp[H-1:]))

Fixed submission:
H,N = map(int,input().split())
AB = [list(map(int, input().split())) for i in range(N)]

M = max(a for a,b in AB)

dp = [0]*(H+M)

for i in range(1,H+M):
    dp[i] = min(dp[i-a]+b for a,b in AB)
    
print(min(dp[H:]))

Buggy python submission (verdict: Runtime Error):
H,N = map(int,input().split())

AB = []

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

dp = [0]*(H+1)

for i in range(H+1):
    dp[i] = min(dp[i-a]+b for a,b in AB)
    
print(dp[H-1])

Fixed submission:
H,N = map(int,input().split())
AB = [list(map(int, input().split())) for i in range(N)]

M = max(a for a,b in AB)

dp = [0]*(H+M)

for i in range(1,H+M):
    dp[i] = min(dp[i-a]+b for a,b in AB)
    
print(min(dp[H:]))

Buggy python submission (verdict: Time Limit Exceeded):
H,N = map(int,input().split())

A = []
B = []

for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)

dp = [1e9]*(H+1)
dp[0] = 0
for i in range(N):
    for j in range(H+1):
        if dp[min(j+A[i],H)] > dp[j] + B[i]:
            dp[min(j+A[i],H)] = dp[j]+B[i]
    
print(dp[H])

Fixed submission:
H,N = map(int,input().split())
AB = [list(map(int, input().split())) for i in range(N)]

M = max(a for a,b in AB)

dp = [0]*(H+M)

for i in range(1,H+M):
    dp[i] = min(dp[i-a]+b for a,b in AB)
    
print(min(dp[H:]))