#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using G = vector<vector<int>>;
int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  LL c;
  cin >> c;
  vector<LL> x(n), v(n);
  for (int i = (0); i < (n); i++) {
    cin >> x[i] >> v[i];
  }
  LL ans = 0;
  LL a = 0;
  for (int i = (0); i < (n); i++) {
    a += v[i];
    ans = max(ans, a - x[i]);
  }
  LL b = 0;
  for (int i = (n)-1; i >= (0); i--) {
    b += v[i];
    ans = max(ans, b - (c - x[i]));
  }
  a = 0;
  for (int i = (0); i < (n); i++) {
    a += v[i];
    b = 0;
    for (int j = (n)-1; j >= (i + 1); j--) {
      b += v[j];
      ans = max(ans, a + b - min(x[i] * 2 + (c - x[j]), (c - x[j]) * 2 + x[i]));
    }
  }
  cout << ans << endl;
  return 0;
}
