#include <bits/stdc++.h>
int main() {
  long long n, c;
  std::cin >> n >> c;
  std::vector<long long> v(n, 0);
  std::vector<long long> x(n, 0);
  for (int i = 0; i < n; ++i) {
    std::cin >> x[i] >> v[i];
  }
  std::vector<long long> clockwise(n, 0);
  std::vector<long long> counterclockwise(n, 0);
  std::vector<long long> clockwise1(n, 0);
  std::vector<long long> counterclockwise1(n, 0);
  long long res = 0;
  long long res1 = 0;
  long long res_other = 0;
  long long res1_other = 0;
  for (int i = 0; i < n; ++i) {
    if (i == 0) {
      clockwise[i] = v[i] - x[i];
    } else {
      clockwise[i] = clockwise[i - 1] + v[i] - (x[i] - x[i - 1]);
    }
    res = std::max(res, clockwise[i]);
    if (i == 0) {
      clockwise1[i] = std::max(clockwise1[i], clockwise[i] - x[i]);
    } else {
      clockwise1[i] = std::max(clockwise[i] - x[i], clockwise1[i - 1]);
    }
    if (i == 0) {
      counterclockwise[i] = v[n - 1 - i] - (c - x[n - 1 - i]);
    } else {
      counterclockwise[i] =
          counterclockwise[i - 1] + v[n - 1 - i] - (x[n - i] - x[n - 1 - i]);
    }
    res_other = std::max(res_other, counterclockwise[i]);
    counterclockwise1[i] = counterclockwise[i] - (c - x[n - 1 - i]);
    if (i == 0) {
      counterclockwise1[i] = std::max(counterclockwise1[i],
                                      counterclockwise[i] - (c - x[n - 1 - i]));
    } else {
      counterclockwise1[i] = std::max(counterclockwise[i] - (c - x[n - 1 - i]),
                                      counterclockwise1[i - 1]);
    }
  }
  for (int i = 0; i < n; ++i) {
    res1 = std::max(res1, clockwise[i] + counterclockwise1[(n - 1) - i - 1]);
    res1_other =
        std::max(res1_other, counterclockwise[i] + clockwise1[(n - 1) - i - 1]);
  }
  long long ans = 0;
  ans = std::max(res, res_other);
  ans = std::max(ans, res1);
  ans = std::max(ans, res1_other);
  std::cout << ans << '\n';
}
