import numpy as np

h, n = list(map(int, input().split()))    

ab = np.array([tuple(map(int, input().split())) for _ in range(n)])

dp = np.zeros(h + 1, dtype="int")

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

    dp[i] = np.min(dp[np.maximum(i - ab[:, 0], 0)] + ab[:, 1])

print((dp[-1]))
import numpy as np

 

h, n = list(map(int, input().split()))

a = []

b = []

for _ in range(n):

  ai, bi = list(map(int, input().split()))

  a.append(ai)

  b.append(bi)

a = np.array(a)

b = np.array(b)

dp = np.zeros(h+1, dtype=np.int)

for c in range(1, h+1):

  dp[c] = np.min(dp[np.maximum(0, c-a)] + b)

print((dp[-1]))
import numpy as np

h, n = list(map(int, input().split()))
ab = np.array([tuple(map(int, input().split())) for _ in range(n)])
dp = np.zeros(h + 1, dtype="int")
for i in range(1, h + 1):
    dp[i] = np.min(dp[np.maximum(i - ab[:, 0], 0)] + ab[:, 1])
print((dp[-1]))

import numpy as np

h, n = list(map(int, input().split()))
a = []
b = []
for _ in range(n):
    ai, bi = list(map(int, input().split()))
    a.append(ai)
    b.append(bi)
a = np.array(a)
b = np.array(b)
dp = np.zeros(h + 1, dtype=np.int)
for c in range(1, h + 1):
    dp[c] = np.min(dp[np.maximum(0, c - a)] + b)
print((dp[-1]))

-ab = np.array([tuple(map(int, input().split())) for _ in range(n)]) -dp = np.zeros(h + 1, dtype="int") -for i in range(1, h + 1): -    dp[i] = np.min(dp[np.maximum(i - ab[:, 0], 0)] + ab[:, 1]) +a = [] +b = [] +for _ in range(n): +    ai, bi = list(map(int, input().split())) +    a.append(ai) +    b.append(bi) +a = np.array(a) +b = np.array(b) +dp = np.zeros(h + 1, dtype=np.int) +for c in range(1, h + 1): +    dp[c] = np.min(dp[np.maximum(0, c - a)] + b)