import java.util.Scanner
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]) {
    solve(new Scanner(System.in))
  }

  def solve(sc: Scanner): Unit = {
    val N = sc.nextInt
    val C = sc.nextLong
    val xv = Array.fill(N)(sc.nextLong, sc.nextInt)

    val p1 = ArrayBuffer(0L)
    val p2 = ArrayBuffer(0L)
    var c = 0L
    for (i <- 0 until N) {
      val (x, v) = xv(i)
      p1 += p1(i) - (x - c) + v
      c = x
    }
    c = 0L
    for (i <- 0 until N) {
      val (x, v) = xv(N - i - 1)
      p2 += p2(i) - ((C - x) - c) + v
      c = C - x
    }
    val p3 = for (i <- 1 to N)
      yield p2.take(N - i + 1).map(_ + p1(i) - xv(i - 1)._1).max
    val p4 = for (i <- 1 to N)
      yield p1.take(N - i + 1).map(_ + p2(i) - (C - xv(N - i)._1)).max

    //    println(p1.mkString(" "))
    //    println(p2.mkString(" "))
    //    println(p3.mkString(" "))
    //    println(p4.mkString(" "))
    val result = List(p1.max, p2.max, p3.max, p4.max).max
    println(result)
  }
}
