import java.util
import java.util.function.ToLongFunction
import java.util.{Comparator, Scanner}

object Main {

  def solve(N: Int, C: Long, p: Array[(Long, Int)]): Long = {
    util.Arrays.sort(p, Comparator.comparingLong(new ToLongFunction[(Long, Int)] {
      override def applyAsLong(v: (Long, Int)): Long = v._1
    }))

    def findMax(indices: Range, x: Long => Long, maxDist: Long, weight: Long): Long = {
      var res: Long = 0
      var eat: Long = 0
      var dist: Long = 0

      for {
        i <- indices
        if x(p(i)._1) <= maxDist
      } {
        eat += p(i)._2
        val move = x(p(i)._1) - dist
        dist += move
        res = math.max(res, eat - dist * weight)
      }
      res
    }

    def clockwise(maxDist: Long, weight: Long): Long = {
      findMax(p.indices, identity, maxDist, weight)
    }

    def counterClockwise(maxDist: Long, weight: Long): Long = {
      findMax(p.indices.reverse, C - _, maxDist, weight)
    }

    def turnOver: Long = {
      // 左 -> 右
      val lr = clockwise(C / 2, 2) + counterClockwise(C / 2, 1)

      // 右 -> 左
      val rl = counterClockwise(C / 2, 2) + clockwise(C / 2, 1)

      math.max(lr, rl)
    }

    math.max(math.max(clockwise(C, 1), counterClockwise(C, 1)), turnOver)
  }

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val N = sc.nextInt()
    val C = sc.nextLong()
    val p = Array.ofDim[(Long, Int)](N)
    p.indices foreach (i => p(i) = (sc.nextLong(), sc.nextInt()))
    println(solve(N, C, p))
  }
}
