#include <bits/stdc++.h>
using namespace std;
long long power(long long b, long long e) {
  long long sol = 1;
  while (e > 0) {
    if (e & 1) {
      sol = sol * b;
    }
    e >>= 1;
    b *= b;
  }
  return sol;
}
long long x[100000];
long long v[100000];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  long long C;
  cin >> N >> C;
  for (int i = (0); i <= (N - 1); ++i) {
    cin >> x[i] >> v[i];
  }
  long long opt = 0;
  long long tmp = 0;
  long long cal = 0;
  for (int i = (0); i <= (N - 1); ++i) {
    tmp = v[i];
    for (int j = (i + 1) % N; j != i; j = (j + 1) % N) {
      tmp += v[j];
      cal = tmp - min(min(x[i], x[j]), min(C - x[i], C - x[j]));
      if (j < i) {
        cal -= x[j] + C - x[i];
      } else {
        cal -= x[j] - x[i];
      }
      opt = max(opt, cal);
    }
  }
  cout << opt << endl;
}
