#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
template <typename T>
T pow(T a, T b, long long m) {
  T ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans % m;
}
long long dist1[100005], dist2[100005], tcal1[100005], tcal2[100005], x[100005],
    cal[100005];
long long fans1[100005], fans2[100005], tfans1[100005], tfans2[100005];
int main() {
  long long n, c;
  cin >> n >> c;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> cal[i];
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    dist1[i] = x[i];
    tcal1[i] += tcal1[i - 1];
    tcal1[i] += cal[i];
    fans1[i] = (tcal1[i] - dist1[i]);
    tfans1[i] = (tcal1[i] - (2 * dist1[i]));
  }
  for (int i = 1; i <= n; i++) {
    ans = max(ans, tcal1[i] - dist1[i]);
  }
  for (int i = n; i >= 1; i--) {
    dist2[i] = (c - x[i]);
    tcal2[i] += tcal2[i + 1];
    tcal2[i] += cal[i];
    fans2[i] = (tcal2[i] - dist2[i]);
    tfans2[i] = (tcal2[i] - 2 * dist2[i]);
  }
  long long ansc1 = 0, ansc2 = 0, anscc1 = 0, anscc2 = 0;
  for (int i = 1; i <= n; i++) {
    if (dist1[i] > c / 2) break;
    ansc1 = max(ansc1, tfans1[i]);
    anscc1 = max(anscc1, fans1[i]);
  }
  for (int i = n; i >= 1; i--) {
    if (dist2[i] > c / 2) break;
    anscc2 = max(anscc2, tfans2[i]);
    ansc2 = max(ansc2, fans2[i]);
  }
  ans = max(ans, max(ansc2 + ansc1, anscc1 + anscc2));
  cout << ans;
  return 0;
}
