object Main extends App {

  import scala.io.StdIn._
  import scala.math._


  val Array(n, d) = readLine.trim.split(' ').map(_.toInt)
  val clue = Array.tabulate(n){_ ⇒
    val Array(t, f) = readLine.trim.split(' ').map(_.toInt)
    Clue(t, f)
  }.sorted
  var passengers = 0
  var floor = 1
  var time = 0
  var sumTime: Long = 0L
  var useStair: Boolean = false
  for (c ← clue if !useStair){
    if (c.floor - 1 + floor - 1 <= c.time - time) {
      //println(s"put ${passengers} passengers to Ground At ${time + floor - 1}")
      sumTime += (floor - 1) * passengers
      passengers = 0
      time += floor - 1
      floor = 1
    }
    if (math.abs(c.floor - floor) <= c.time - time && passengers < d){
      //println(s"take ${c} passenger (whole ${passengers + 1}) At ${c.time}")
      sumTime += (c.time - time) * passengers
      passengers += 1
      time = c.time
      floor = c.floor
    } else {
      //println(s"can't take $c passenger, elevator ${floor} floor, ${passengers} passengers at ${time} ")
      useStair = true
    }
  }
  sumTime += passengers * (floor - 1)
  println(
    if (useStair) -1
    else sumTime
  )

  case class Clue(time: Int, floor: Int) extends Ordered[Clue] {
    override def compare(that: Clue): Int = time.compare(that.time)
  }

  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}
