#include <bits/stdc++.h>
using namespace std;
const int INF = (int)INFINITY;
long long n, c, x[200003];
long long ans;
long long now;
int v[10003];
int main() {
  ;
  int l;
  long long p;
  cin >> n >> c;
  for (int i = 1; i <= n; i++) {
    cin >> x[10000 + i] >> v[i];
    x[10000 - n - 1 + i] = c - x[10000 + i];
  }
  for (int r = 10001; r <= 10000 + n + 1; r++) {
    l = 10000 - (n - (r - 10000) + 1);
    now = 0;
    for (p = 10001; p < r; p++) {
      now -= (x[p] - x[p - 1]);
      now += v[p - 10000];
      ans = max(ans, now);
    }
    now -= x[p - 1];
    for (p = 9999; p >= l; p--) {
      now -= (x[p] - x[p + 1]);
      now += v[n - (10000 - p) + 1];
      ans = max(ans, now);
    }
    now = 0;
    for (p = 9999; p >= l; p--) {
      now -= (x[p] - x[p + 1]);
      now += v[n - (10000 - p) + 1];
      ans = max(ans, now);
    }
    now -= (x[p + 1]);
    for (p = 10001; p < r; p++) {
      now -= (x[p] - x[p - 1]);
      now += v[p - 10000];
      ans = max(ans, now);
    }
  }
  cout << ans;
  return 0;
}
