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)



DP=[[0]*(H+1) for i in range(N)]

DP.insert(0,[float("inf")]*(H+max(A)))

DP[0][0]=0



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

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

      if j-A[i-1]>0:

         DP[i][j]=min(DP[i-1][j],DP[i][j-A[i-1]]+B[i-1])

      else:

         DP[i][j]=min(DP[i-1][j],B[i-1])



print((DP[N][H]))
from sys import stdin

import numpy as np

def main():

    #入力

    readline=stdin.readline

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

    ab=np.array([list(map(int,readline().split())) for _ in range(n)],dtype=np.int64)

    a=ab[:,0]

    b=ab[:,1]



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

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

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



    print((dp[h]))



if __name__=="__main__":

    main()
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)
DP = [[0] * (H + 1) for i in range(N)]
DP.insert(0, [float("inf")] * (H + max(A)))
DP[0][0] = 0
for i in range(1, N + 1):
    for j in range(1, H + 1):
        if j - A[i - 1] > 0:
            DP[i][j] = min(DP[i - 1][j], DP[i][j - A[i - 1]] + B[i - 1])
        else:
            DP[i][j] = min(DP[i - 1][j], B[i - 1])
print((DP[N][H]))

from sys import stdin
import numpy as np


def main():
    # 入力
    readline = stdin.readline
    h, n = list(map(int, readline().split()))
    ab = np.array(
        [list(map(int, readline().split())) for _ in range(n)], dtype=np.int64
    )
    a = ab[:, 0]
    b = ab[:, 1]
    dp = np.zeros(h + 1, dtype=np.int64)
    for i in range(1, h + 1):
        dp[i] = (dp[np.maximum(0, i - a)] + b).min()
    print((dp[h]))


if __name__ == "__main__":
    main()

-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) -DP = [[0] * (H + 1) for i in range(N)] -DP.insert(0, [float("inf")] * (H + max(A))) -DP[0][0] = 0 -for i in range(1, N + 1): -    for j in range(1, H + 1): -        if j - A[i - 1] > 0: -            DP[i][j] = min(DP[i - 1][j], DP[i][j - A[i - 1]] + B[i - 1]) -        else: -            DP[i][j] = min(DP[i - 1][j], B[i - 1]) -print((DP[N][H])) +from sys import stdin +import numpy as np + + +def main(): +    # 入力 +    readline = stdin.readline +    h, n = list(map(int, readline().split())) +    ab = np.array( +        [list(map(int, readline().split())) for _ in range(n)], dtype=np.int64 +    ) +    a = ab[:, 0] +    b = ab[:, 1] +    dp = np.zeros(h + 1, dtype=np.int64) +    for i in range(1, h + 1): +        dp[i] = (dp[np.maximum(0, i - a)] + b).min() +    print((dp[h])) + + +if __name__ == "__main__": +    main()