#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool setmin(T& a, T b) {
  if (b < a) {
    a = b;
    return true;
  } else {
    return false;
  }
}
template <typename T>
bool setmax(T& a, T b) {
  if (b > a) {
    a = b;
    return true;
  } else {
    return false;
  }
}
template <typename T>
bool setmineq(T& a, T b) {
  if (b <= a) {
    a = b;
    return true;
  } else {
    return false;
  }
}
template <typename T>
bool setmaxeq(T& a, T b) {
  if (b >= a) {
    a = b;
    return true;
  } else {
    return false;
  }
}
template <typename T>
T gcd(T a, T b) {
  return (b == 0 ? a : gcd(b, a % b));
}
template <typename T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
const int M = 100000;
long long signed int n, c, x[M + 2], v[M + 2];
long long signed int a[M + 2], b[M + 2];
long long signed int f() {
  long long signed int s = 0;
  for (int i = (1); i <= (n); i++) {
    s += v[i] - abs(x[i] - x[i - 1]) * 2;
    a[i] = max(s, a[i - 1]);
  }
  s = 0;
  for (int i = (n); i >= (1); i--) {
    s += v[i] - abs(x[i] - x[i + 1]);
    b[i] = max(s, b[i + 1]);
  }
  long long signed int ans = 0;
  for (int i = (0); i <= (n); i++) {
    setmax(ans, a[i] + b[i + 1]);
  }
  return ans;
}
void flip() {
  for (int i = (0); i < ((n + 1) / 2); i++) {
    swap(x[i], x[n + 1 - i]);
    swap(v[i], v[n + 1 - i]);
  }
  for (int i = (0); i < (n + 2); i++) {
    x[i] = c - x[i];
  }
}
int main() {
  cin >> n >> c;
  x[0] = 0;
  v[0] = 0;
  for (int i = (1); i <= (n); i++) {
    cin >> x[i] >> v[i];
  }
  x[n + 1] = c;
  v[n + 1] = 0;
  long long signed int ans = 0;
  setmax(ans, f());
  flip();
  setmax(ans, f());
  cout << ans << endl;
  return 0;
}
