def getN():

    return int(eval(input()))

def getNM():

    return list(map(int, input().split()))

def getList():

    return list(map(int, input().split()))

def getArray(intn):

    return [int(eval(input())) for i in range(intn)]

def input():

    return sys.stdin.readline().rstrip()



from collections import defaultdict, deque, Counter

from sys import exit

import heapq

import math

import copy

from operator import mul

from functools import reduce

from bisect import bisect_left, bisect_right



import sys

sys.setrecursionlimit(1000000000)

mod = 10 ** 9 + 7



H, N = getNM()

magic = []

for i in range(N):

    a, b = getNM()

    # AがATC,BがMP

    magic.append([a, b])



dp = [float('inf')] * (H + 1)

dp[0] = 0

# HP = iを削るための最小MP

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

    for j in magic:

        if i < j[0]:

            dp[i] = min(dp[i], j[1])

        else:

            dp[i] = min(dp[i], dp[i - j[0]] + j[1])

print((dp[-1]))

def getN():

    return int(eval(input()))

def getNM():

    return list(map(int, input().split()))

def getList():

    return list(map(int, input().split()))

def getArray(intn):

    return [int(eval(input())) for i in range(intn)]

def input():

    return sys.stdin.readline().rstrip()

def rand_N(ran1, ran2):

    return random.randint(ran1, ran2)

def rand_List(ran1, ran2, rantime):

    return [random.randint(ran1, ran2) for i in range(rantime)]

def rand_ints_nodup(ran1, ran2, rantime):

  ns = []

  while len(ns) < rantime:

    n = random.randint(ran1, ran2)

    if not n in ns:

      ns.append(n)

  return sorted(ns)



def rand_query(ran1, ran2, rantime):

  r_query = []

  while len(r_query) < rantime:

    n_q = rand_ints_nodup(ran1, ran2, 2)

    if not n_q in r_query:

      r_query.append(n_q)

  return sorted(r_query)



from collections import defaultdict, deque, Counter

from sys import exit

from decimal import *

from heapq import heapify, heappop, heappush

import math

import random

import string

from copy import deepcopy

from itertools import combinations, permutations, product

from operator import mul, itemgetter

from functools import reduce

from bisect import bisect_left, bisect_right



import sys

sys.setrecursionlimit(1000000000)

mod = 10 ** 9 + 7



#############

# Main Code #

#############



N, M = getNM()

W = []

V = []

for i in range(M):

    a, b = getNM()

    W.append(b)

    V.append(a)



# magicを重複ありで適当に組み合わせて合計Nを目指す

def knapsack_4(N, limit, weight, value):

    dp = [float('inf')] * (limit + 1)

    dp[0] = 0



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

        for j in range(N):

            if i < value[j]:

                dp[i] = min(dp[i], weight[j])

            else:

                dp[i] = min(dp[i], dp[i - value[j]] + weight[j])

    return dp[-1]

print((knapsack_4(M, N, W, V)))

def getN():
    return int(eval(input()))


def getNM():
    return list(map(int, input().split()))


def getList():
    return list(map(int, input().split()))


def getArray(intn):
    return [int(eval(input())) for i in range(intn)]


def input():
    return sys.stdin.readline().rstrip()


from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys

sys.setrecursionlimit(1000000000)
mod = 10**9 + 7
H, N = getNM()
magic = []
for i in range(N):
    a, b = getNM()
    # AがATC,BがMP
    magic.append([a, b])
dp = [float("inf")] * (H + 1)
dp[0] = 0
# HP = iを削るための最小MP
for i in range(1, H + 1):
    for j in magic:
        if i < j[0]:
            dp[i] = min(dp[i], j[1])
        else:
            dp[i] = min(dp[i], dp[i - j[0]] + j[1])
print((dp[-1]))

def getN():
    return int(eval(input()))


def getNM():
    return list(map(int, input().split()))


def getList():
    return list(map(int, input().split()))


def getArray(intn):
    return [int(eval(input())) for i in range(intn)]


def input():
    return sys.stdin.readline().rstrip()


def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)


def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]


def rand_ints_nodup(ran1, ran2, rantime):
    ns = []
    while len(ns) < rantime:
        n = random.randint(ran1, ran2)
        if not n in ns:
            ns.append(n)
    return sorted(ns)


def rand_query(ran1, ran2, rantime):
    r_query = []
    while len(r_query) < rantime:
        n_q = rand_ints_nodup(ran1, ran2, 2)
        if not n_q in r_query:
            r_query.append(n_q)
    return sorted(r_query)


from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right
import sys

sys.setrecursionlimit(1000000000)
mod = 10**9 + 7
#############
# Main Code #
#############
N, M = getNM()
W = []
V = []
for i in range(M):
    a, b = getNM()
    W.append(b)
    V.append(a)
# magicを重複ありで適当に組み合わせて合計Nを目指す
def knapsack_4(N, limit, weight, value):
    dp = [float("inf")] * (limit + 1)
    dp[0] = 0
    for i in range(1, limit + 1):
        for j in range(N):
            if i < value[j]:
                dp[i] = min(dp[i], weight[j])
            else:
                dp[i] = min(dp[i], dp[i - value[j]] + weight[j])
    return dp[-1]


print((knapsack_4(M, N, W, V)))

+def rand_N(ran1, ran2): +    return random.randint(ran1, ran2) + + +def rand_List(ran1, ran2, rantime): +    return [random.randint(ran1, ran2) for i in range(rantime)] + + +def rand_ints_nodup(ran1, ran2, rantime): +    ns = [] +    while len(ns) < rantime: +        n = random.randint(ran1, ran2) +        if not n in ns: +            ns.append(n) +    return sorted(ns) + + +def rand_query(ran1, ran2, rantime): +    r_query = [] +    while len(r_query) < rantime: +        n_q = rand_ints_nodup(ran1, ran2, 2) +        if not n_q in r_query: +            r_query.append(n_q) +    return sorted(r_query) + + -import heapq +from decimal import * +from heapq import heapify, heappop, heappush -import copy -from operator import mul +import random +import string +from copy import deepcopy +from itertools import combinations, permutations, product +from operator import mul, itemgetter -H, N = getNM() -magic = [] -for i in range(N): +############# +# Main Code # +############# +N, M = getNM() +W = [] +V = [] +for i in range(M): -    # AがATC,BがMP -    magic.append([a, b]) -dp = [float("inf")] * (H + 1) -dp[0] = 0 -# HP = iを削るための最小MP -for i in range(1, H + 1): -    for j in magic: -        if i < j[0]: -            dp[i] = min(dp[i], j[1]) -        else: -            dp[i] = min(dp[i], dp[i - j[0]] + j[1]) -print((dp[-1])) +    W.append(b) +    V.append(a) +# magicを重複ありで適当に組み合わせて合計Nを目指す +def knapsack_4(N, limit, weight, value): +    dp = [float("inf")] * (limit + 1) +    dp[0] = 0 +    for i in range(1, limit + 1): +        for j in range(N): +            if i < value[j]: +                dp[i] = min(dp[i], weight[j]) +            else: +                dp[i] = min(dp[i], dp[i - value[j]] + weight[j]) +    return dp[-1] + + +print((knapsack_4(M, N, W, V)))