#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& a) {
  return os << "(" << a.first << "," << a.second << ")";
}
template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << (*i) << " ";
  cout << endl;
}
template <class T>
void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
int nxint() {
  int x;
  scanf("%d", &x);
  return x;
}
long long x[100005], v[100005];
struct pos {
  long long b, e, d;
  pos(int x, int y, int z) : b(x), e(y), d(z) {}
};
void upd(long long x, long long y, queue<pos>& que,
         map<pair<int, int>, int>& mp, long long& ans, long long v) {
  if (mp.find(make_pair((x), (y))) != mp.end() && mp[make_pair((x), (y))] < v) {
    que.push(pos(x, y, v));
    mp[make_pair((x), (y))] = v;
    ans = max(ans, v);
    cout << x << ' ' << y << ' ' << v << endl;
  }
}
int main() {
  long long n, C;
  while (cin >> n >> C) {
    for (int i = 0, _n = (int)(n); i < _n; ++i) cin >> x[i] >> v[i];
    queue<pos> que;
    map<pair<int, int>, int> mp;
    que.push(pos(0, n - 1, v[0] - x[0]));
    mp[make_pair(0, n - 1)] = v[0] - x[0];
    que.push(pos(n - 1, 0, v[n - 1] - C + x[n - 1]));
    mp[make_pair(n - 1, 0)] = v[n - 1] - C + x[n - 1];
    long long ans = 0;
    ans = max(0LL, max(v[0] - x[0], v[n - 1] - C + x[n - 1]));
    while (!que.empty()) {
      pos p = que.front();
      que.pop();
      if (p.b < p.e) {
        long long t = v[p.b + 1] - x[p.b + 1] + x[p.b];
        upd(p.b + 1, p.e, que, mp, ans, p.d + t);
        t = v[p.e] - x[p.b] - (C - x[p.e]);
        upd(p.e, p.b + 1, que, mp, ans, p.d + t);
      } else if (p.b > p.e) {
        long long t = v[p.b - 1] - x[p.b] + x[p.b - 1];
        upd(p.b - 1, p.e, que, mp, ans, p.d + t);
        t = v[p.e] - x[p.e] - (C - x[p.b]);
        upd(p.e, p.b - 1, que, mp, ans, p.d + t);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
