#include <bits/stdc++.h>
;
using namespace std;
template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1) s << "\t";
  }
  return s;
}
template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}
long long N, C;
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> C;
  vector<long long> x;
  vector<long long> v;
  for (long long i = 0; i < (N); i++) {
    long long tx, tv;
    cin >> tx >> tv;
    x.push_back(tx);
    v.push_back(tv);
  }
  long long ans = 0;
  for (long long k = 0; k < (N); k++) {
    long long start = k;
    long long cur = 0;
    long long s = 0;
    for (long long j = 0; j < (N); j++) {
      long long i = (start + j) % N;
      long long d;
      if (abs(x[i] - cur) > C / 2) {
        d = C - abs(x[i] - cur);
      } else {
        d = abs(x[i] - cur);
      }
      s = s - d + v[i];
      cur = x[i];
      if (s > ans) {
        ans = s;
      }
    }
    start = k;
    cur = s = 0;
    for (long long j = (N)-1; j >= 0; j--) {
      long long i = (start + j) % N;
      long long d;
      if (abs(x[i] - cur) > C / 2) {
        d = C - abs(x[i] - cur);
      } else {
        d = abs(x[i] - cur);
      }
      s = s - d + v[i];
      cur = x[i];
      if (s > ans) {
        ans = s;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
