import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt  // num
  val C = in.next().toLong  // dist
  val x = new Array[Long](N+1) // dist
  val v = new Array[Long](N+1) // ene
  for(i <- 1 to N){
    val a, b = in.next().toLong
    x(i) = a
    v(i) = b
  }


  //
  import Math._

  var ans = 0L

  var cnt = 0L
  for(i <- 1 to N) {
    cnt += v(i)
    ans = max(ans, cnt-x(i))
  }


  cnt = 0L
  val dp = new Array[Long](N+2) // dist
  for(i <- (1 to N).reverse) {
    cnt += v(i)
    val now = cnt - (C - x(i))
    ans = max(ans, now)
    dp(i) = max(dp(i+1), now)
  }


  cnt = 0L
  for(i <- 1 to N) {
    cnt += v(i)
    val now = cnt - 2*x(i) + dp(i+1)
    ans = max(ans, now)
  }

  println(ans)
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}

