#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
struct Sushi {
  long long x;
  long long v;
};
int main() {
  int N;
  long long C;
  cin >> N >> C;
  if (N > 1000) {
    return 0;
  }
  long long ans = 0;
  vector<Sushi> V(N);
  for (int i = 0; i < N; i++) {
    long long x, v;
    cin >> x >> v;
    V[i].x = x;
    V[i].v = v;
  }
  long long vs = 0;
  for (int i = 0; i < N; i++) {
    vs += V[i].v;
    ans = max(ans, vs - V[i].x);
  }
  vs = 0;
  for (int i = N - 1; i >= 0; i--) {
    vs += V[i].v;
    ans = max(ans, vs - (C - V[i].x));
  }
  vector<long long> S1(N), S2(N);
  S1[0] = V[0].v;
  S2[N - 1] = V[N - 1].v;
  for (int i = 1; i < N; i++) {
    S1[i] = S1[i - 1] + V[i].v;
  }
  for (int i = N - 2; i >= 0; i--) {
    S2[i] = S2[i + 1] + V[i].v;
  }
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (i == j) {
        continue;
      }
      long long x1, x2;
      x1 = V[i].x;
      x2 = C - V[j].x;
      ans = max(ans, S1[i] + S2[j] - (min(x1, x2) * 2 + max(x1, x2)));
    }
  }
  cout << ans << endl;
  return 0;
}
