#include <bits/stdc++.h>
using namespace std;
template <typename X>
bool exist(vector<X> vec, X item) {
  return find(vec.begin(), vec.end(), item) != vec.end();
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long N, C;
vector<long long> x, v;
long long le[1000005];
long long leo[1000005];
long long ri[1000005];
long long rio[1000005];
void set() {
  long long now = 0;
  long long before = 0;
  long long beforeo = 0;
  for (long long i = (long long)0; i < (long long)N; i++) {
    now += v[i];
    if ((now - x[i] - x[i]) > beforeo)
      leo[i] = now - x[i] - x[i];
    else
      leo[i] = beforeo;
    if ((now - x[i]) >= before) {
      le[i] = now - x[i];
      before = now - x[i];
    } else
      le[i] = before;
  }
  now = 0;
  before = 0;
  beforeo = 0;
  for (long long i = N - 1; i >= 0; i--) {
    now += v[i];
    if ((now - (C - x[i]) - (C - x[i])) > beforeo)
      rio[i] = now - (C - x[i]) - (C - x[i]);
    else
      rio[i] = beforeo;
    if ((now - (C - x[i])) >= before) {
      ri[i] = now - (C - x[i]);
      before = now - (C - x[i]);
    } else
      ri[i] = before;
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> C;
  x.push_back(0);
  v.push_back(0);
  for (long long i = (long long)0; i < (long long)N; i++) {
    long long xi, vi;
    cin >> xi >> vi;
    x.push_back(xi);
    v.push_back(vi);
  }
  N++;
  set();
  long long ans = 0;
  for (long long i = (long long)0; i < (long long)N - 1; i++) {
    long long sum1, sum2;
    if (i == 0) {
      sum1 = 0;
      sum2 = ri[0];
    } else {
      sum1 = le[i] + rio[i + 1];
      sum2 = leo[i] + ri[i + 1];
      ans = max(ans, sum1);
      ans = max(ans, sum2);
    }
  }
  cout << ans << endl;
  return 0;
}
