H,N = list(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:])))
import numpy as np 



H,N = list(map(int,input().split()))



A = []

B = []



for i in range(N):

    a,b = list(map(int,input().split()))

    A.append(a)

    B.append(b)



A = np.array(A)

B = np.array(B)



dp = np.zeros(H+1,dtype=np.int32)



for i in range(1,H+1):

    dp[i] = np.amin(dp[np.maximum(i-A,0)]+B)

    

print((dp[H]))
H, N = list(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:])))

import numpy as np

H, N = list(map(int, input().split()))
A = []
B = []
for i in range(N):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)
A = np.array(A)
B = np.array(B)
dp = np.zeros(H + 1, dtype=np.int32)
for i in range(1, H + 1):
    dp[i] = np.amin(dp[np.maximum(i - A, 0)] + B)
print((dp[H]))

+import numpy as np + -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:]))) +A = [] +B = [] +for i in range(N): +    a, b = list(map(int, input().split())) +    A.append(a) +    B.append(b) +A = np.array(A) +B = np.array(B) +dp = np.zeros(H + 1, dtype=np.int32) +for i in range(1, H + 1): +    dp[i] = np.amin(dp[np.maximum(i - A, 0)] + B) +print((dp[H]))