object Main extends App {
  import scala.io.StdIn._
  solve
  def solve: Unit = {
    val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
    println(
      Array.tabulate(m){_ ⇒
        val Array(a, _) = readLine.trim.split(' ').map(_.toInt)
        n - a
      }.sorted.dropRight(1).filter(_ > 0).sum
    )
  }
  implicit class ScopeFunc[T](private val value: T) {
    def let[A](func:T ⇒ A): A = func(value)
    def also(func:T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}


