import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val H, N = in.next().toInt
  val ms = new Array[(Int, Int)](N)
  for (i <- 0 until N) {
    val A, B = in.next().toInt
    ms(i) = (A, B)
  }

  //
  var dp = Array.fill[Int](H+1)(Int.MaxValue)
  dp(0) = 0

  for ((a, b) <- ms) {
    for (i <- (0 to H)) {
      if (dp(i) != Int.MaxValue) {
        if (i + a > H) {
          dp(H) = Math.min(dp(H), dp(i) + b)
        }
        else {
          dp(i+a) = Math.min(dp(i+a), dp(i) + b)
        }
      }
    }
  }

  println(dp(H))
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}
