object Main extends App {
  import scala.io.StdIn._
  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val section = Array.fill(n){
    val Array(l, r) = readLine.trim.split(' ').map(_.toInt)
    Array(l, -r)
  }.flatten.sortWith{(a, b) ⇒ if (a.abs != b.abs) a.abs < b.abs else b < a}
  var maxSection = 0
  var minPos = m
  var maxPos = 0
  var current = 0
  for (i ← section) {
    if (i > 0) {
      current += 1
      if (maxSection == current) {
        maxPos = i
      }else if (maxSection < current) {
        minPos = i
        maxPos = i
        maxSection = current
      }
    }else {
      current -= 1
      if (maxSection == current + 1) {
        maxPos = -i
      }
    }
  }
  println(
    if (maxSection % 2 == 0) maxSection.toLong * m - minPos
    else maxSection.toLong * m + maxPos - m
  )
}
