#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
struct poi {
  int X;
  int Y;
  int Z;
  bool operator<(const poi& R) const {
    return X == R.X ? Y == R.Y ? Z < R.Z : Y < R.Y : X < R.X;
  }
};
long long N, C;
long long X[100001], V[100001];
long long v[100001];
long long rv[100001];
long long n[100001];
int main() {
  cin >> N >> C;
  X[0] = 0;
  V[0] = 0;
  for (int i = 1; i < N + 1; i++) {
    cin >> X[i] >> V[i];
  }
  v[0] = 0;
  for (int i = 1; i < N + 1; i++) {
    v[i] = v[i - 1] + V[i];
  }
  for (int i = 1; i < N + 1; i++) {
    v[i] -= X[i];
  }
  int now = 0;
  n[0] = 0;
  for (int i = 1; i < N + 1; i++) {
    if (v[now] < v[i]) {
      now = i;
    }
    n[i] = now;
  }
  reverse(X + 1, X + N + 1);
  reverse(V + 1, V + N + 1);
  rv[0] = 0;
  for (int i = 1; i < N + 1; i++) {
    rv[i] = rv[i - 1] + V[i];
  }
  for (int i = 1; i < N + 1; i++) {
    rv[i] -= C - X[i];
  }
  long long ans = 0;
  reverse(X + 1, X + N + 1);
  reverse(V + 1, V + N + 1);
  for (int i = 0; i < N + 1; i++) {
    if (i != 0) {
      v[n[N - 1 - i]] -= X[n[N - 1 - i]];
    }
    ans = max(ans, rv[i] + v[n[N - 1 - i]]);
  }
  fill(v, v + N + 1, 0);
  fill(rv, rv + N + 1, 0);
  fill(n, n + N + 1, 0);
  reverse(X + 1, X + N + 1);
  reverse(V + 1, V + N + 1);
  for (int i = 1; i < N + 1; i++) {
    X[i] = C - X[i];
  }
  v[0] = 0;
  for (int i = 1; i < N + 1; i++) {
    v[i] = v[i - 1] + V[i];
  }
  for (int i = 1; i < N + 1; i++) {
    v[i] -= X[i];
  }
  now = 0;
  n[0] = 0;
  for (int i = 1; i < N + 1; i++) {
    if (v[now] < v[i]) {
      now = i;
    }
    n[i] = now;
  }
  reverse(X + 1, X + N + 1);
  reverse(V + 1, V + N + 1);
  rv[0] = 0;
  for (int i = 1; i < N + 1; i++) {
    rv[i] = rv[i - 1] + V[i];
  }
  for (int i = 1; i < N + 1; i++) {
    rv[i] -= C - X[i];
  }
  reverse(X + 1, X + N + 1);
  reverse(V + 1, V + N + 1);
  for (int i = 0; i < N + 1; i++) {
    if (i != 0) {
      v[n[N - 1 - i]] -= X[n[N - 1 - i]];
    }
    ans = max(ans, rv[i] + v[n[N - 1 - i]]);
  }
  cout << ans << endl;
  return 0;
}
