output_description: Print the minimum total Magic Points that have to be consumed before winning.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      H N
      A_1 B_1
      :
      A_N B_N
attempt: h, n = list(map(int, input().split()))
  
  hp_and_magic = [list(map(int, input().split())) for _ in range(n)]
  
  arr = [0] * (h + 1)
  # arr[k] := hpがkの敵を倒すのに必要な最小魔力
  
  arr[1] = min([ele[1] for ele in hp_and_magic])
  for i in range(2, h + 1):
      arr[i] = 10**9
      for ele in hp_and_magic:
          if i - ele[0] >= 0:
              arr[i] = min(arr[i], arr[i - ele[0]] + ele[1])
              # print(arr[i-ele[0]], ele[1])
  
  print(arr[h])
  
problem_description: Statement
  
  Ibis is fighting with a monster.
  
  The _health_ of the monster is H.
  
  Ibis can cast N kinds of spells. Casting the i-th spell decreases the
  monster's health by A_i, at the cost of B_i Magic Points.
  
  The same spell can be cast multiple times. There is no way other than spells
  to decrease the monster's health.
  
  Ibis wins when the health of the monster becomes 0 or below.
  
  Find the minimum total Magic Points that have to be consumed before winning.
samples: [{"input": "9 3\n    8 3\n    4 2\n    2 1", "output": "4\n    \n\nFirst, let us cast the first spell to decrease the monster's health by 8, at\nthe cost of 3 Magic Points. The monster's health is now 1.\n\nThen, cast the third spell to decrease the monster's health by 2, at the cost\nof 1 Magic Point. The monster's health is now -1.\n\nIn this way, we can win at the total cost of 4 Magic Points.\n\n* * *"}, {"input": "100 6\n    1 1\n    2 3\n    3 9\n    4 27\n    5 81\n    6 243", "output": "100\n    \n\nIt is optimal to cast the first spell 100 times.\n\n* * *"}, {"input": "9999 10\n    540 7550\n    691 9680\n    700 9790\n    510 7150\n    415 5818\n    551 7712\n    587 8227\n    619 8671\n    588 8228\n    176 2461", "output": "139815"}]