#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
inline bool chmax(A &a, B b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename A, typename B>
inline bool chmin(A &a, B b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1e9 + 100;
const long long INFL = 1e18 + 100;
const long long MOD = 1e9 + 7;
const bool debug = 0;
long long N, C;
long long x[112345], v[112345];
long long ma[112345];
long long solve() {
  fill(ma, ma + N + 1, -INFL);
  ma[N] = 0;
  x[N] = C;
  for (int i = N - 1; i >= 0; i--) ma[i] = ma[i + 1] + v[i] - (x[i + 1] - x[i]);
  for (int i = N - 1; i >= 0; i--) chmax(ma[i], ma[i + 1]);
  long long res = ma[0];
  long long sum = 0;
  for (int i = (0); i < (N); ++i) {
    sum += v[i];
    long long cur = -x[i] + sum;
    chmax(res, cur);
    cur -= x[i];
    cur += ma[i + 1];
    chmax(res, cur);
  }
  return res;
}
int main() {
  cin >> N >> C;
  for (int i = (0); i < (N); ++i) scanf("%lld %lld", x + i, v + i);
  long long ans = solve();
  for (int i = (0); i < (N); ++i) x[i] = C - x[i];
  sort(x, x + N + 1);
  chmax(ans, solve());
  cout << ans << endl;
  return 0;
}
