import sys

sys.setrecursionlimit(10**9)



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

magic = [_ for _ in range(N)]



for k in range(N):

  magic[k] = list(map(int, input().split()))

  magic[k].append(magic[k][0]/magic[k][1])



magic.sort(key = lambda x: x[2], reverse=True)

ans = [0 for _ in range(H+1)]

visited = [0]

anskouho = [float('inf')]



def solve(start, power, point, maryoku):

  if start == H:

    print((min(point, min(anskouho))))

    exit()

  elif start > H:

    anskouho.append(point)

    return 0

  elif ans[start] != 0:

    return 0

  else:

    visited.append(start)

    ans[start] = point

    solve(start+power, power, point+maryoku, maryoku)



for k in range(N):

  for item in visited:

    solve(item+magic[k][0], magic[k][0], ans[item] + magic[k][1], magic[k][1])



print((min(anskouho)))
#import sys

#sys.setrecursionlimit(10**9)



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

magic = [_ for _ in range(N)]



for k in range(N):

  magic[k] = list(map(int, input().split()))

  magic[k].append(magic[k][0]/magic[k][1])



magic.sort(key = lambda x: x[2], reverse=True)

ans = [0 for _ in range(H+1)]

visited = [0]

anskouho = [float('inf')]

ans2 = float('inf')

"""

def solve(start, power, point, maryoku):

  if start == H:

    print(min(point, min(anskouho)))

    exit()

  elif start > H:

    anskouho.append(point)

    return 0

  elif ans[start] != 0:

    return 0

  else:

    visited.append(start)

    ans[start] = point

    solve(start+power, power, point+maryoku, maryoku)

"""

for k in range(N):

  for item in visited:

    #solve(item+magic[k][0], magic[k][0], ans[item] + magic[k][1], magic[k][1])

    start = item+magic[k][0]

    power = magic[k][0]

    point = ans[item]+ magic[k][1]

    maryoku = magic[k][1]

    for _ in range(10**5):

      if start == H:

        print((min(point, ans2)))

        exit()

      elif start > H:

        ans2 = min(ans2, point)

        break

      elif ans[start]!=0:

        break

      else:

        visited.append(start)

        ans[start] = point

        start += power

        point += maryoku

      

print(ans2)
import sys

sys.setrecursionlimit(10**9)
H, N = list(map(int, input().split()))
magic = [_ for _ in range(N)]
for k in range(N):
    magic[k] = list(map(int, input().split()))
    magic[k].append(magic[k][0] / magic[k][1])
magic.sort(key=lambda x: x[2], reverse=True)
ans = [0 for _ in range(H + 1)]
visited = [0]
anskouho = [float("inf")]


def solve(start, power, point, maryoku):
    if start == H:
        print((min(point, min(anskouho))))
        exit()
    elif start > H:
        anskouho.append(point)
        return 0
    elif ans[start] != 0:
        return 0
    else:
        visited.append(start)
        ans[start] = point
        solve(start + power, power, point + maryoku, maryoku)


for k in range(N):
    for item in visited:
        solve(item + magic[k][0], magic[k][0], ans[item] + magic[k][1], magic[k][1])
print((min(anskouho)))

# import sys
# sys.setrecursionlimit(10**9)
H, N = list(map(int, input().split()))
magic = [_ for _ in range(N)]
for k in range(N):
    magic[k] = list(map(int, input().split()))
    magic[k].append(magic[k][0] / magic[k][1])
magic.sort(key=lambda x: x[2], reverse=True)
ans = [0 for _ in range(H + 1)]
visited = [0]
anskouho = [float("inf")]
ans2 = float("inf")
"""
def solve(start, power, point, maryoku):
  if start == H:
    print(min(point, min(anskouho)))
    exit()
  elif start > H:
    anskouho.append(point)
    return 0
  elif ans[start] != 0:
    return 0
  else:
    visited.append(start)
    ans[start] = point
    solve(start+power, power, point+maryoku, maryoku)
"""
for k in range(N):
    for item in visited:
        # solve(item+magic[k][0], magic[k][0], ans[item] + magic[k][1], magic[k][1])
        start = item + magic[k][0]
        power = magic[k][0]
        point = ans[item] + magic[k][1]
        maryoku = magic[k][1]
        for _ in range(10**5):
            if start == H:
                print((min(point, ans2)))
                exit()
            elif start > H:
                ans2 = min(ans2, point)
                break
            elif ans[start] != 0:
                break
            else:
                visited.append(start)
                ans[start] = point
                start += power
                point += maryoku
print(ans2)

-import sys - -sys.setrecursionlimit(10**9) +# import sys +# sys.setrecursionlimit(10**9) - - +ans2 = float("inf") +""" -    if start == H: -        print((min(point, min(anskouho)))) -        exit() -    elif start > H: -        anskouho.append(point) -        return 0 -    elif ans[start] != 0: -        return 0 -    else: -        visited.append(start) -        ans[start] = point -        solve(start + power, power, point + maryoku, maryoku) - - +  if start == H: +    print(min(point, min(anskouho))) +    exit() +  elif start > H: +    anskouho.append(point) +    return 0 +  elif ans[start] != 0: +    return 0 +  else: +    visited.append(start) +    ans[start] = point +    solve(start+power, power, point+maryoku, maryoku) +""" -        solve(item + magic[k][0], magic[k][0], ans[item] + magic[k][1], magic[k][1]) -print((min(anskouho))) +        # solve(item+magic[k][0], magic[k][0], ans[item] + magic[k][1], magic[k][1]) +        start = item + magic[k][0] +        power = magic[k][0] +        point = ans[item] + magic[k][1] +        maryoku = magic[k][1] +        for _ in range(10**5): +            if start == H: +                print((min(point, ans2))) +                exit() +            elif start > H: +                ans2 = min(ans2, point) +                break +            elif ans[start] != 0: +                break +            else: +                visited.append(start) +                ans[start] = point +                start += power +                point += maryoku +print(ans2)