object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val c = sc.nextLong()
  val xv = Array.fill(n)((sc.nextLong(), sc.nextLong()))
  val fc = xv.scanLeft((0L, 0L)){case ((_, vc), (x, v)) => (x, vc + v)}
  val fcMax = fc.scanLeft((0L, 0L)){case ((_, m), (xc, vc)) => (xc, m.max(vc - xc))}.tail
  val bc = xv.scanRight((0L, 0L)){case ((x, v), (_, vc)) => (c - x, vc + v)}
  val bcMax = bc.scanRight((0L, 0L)){case ((xc, vc), (_, m)) => (xc, m.max(vc - xc))}.init
  println(fcMax.zip(bcMax).map{case ((xf, mf), (xb, mb)) => mf + mb - xf.min(xb)}.max)
}
