#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int main() {
  unsigned long long N, C;
  unsigned long long x[100002], v[100002];
  cin >> N >> C;
  x[0] = v[0] = 0LL;
  x[N + 1] = C;
  v[N + 1] = 0LL;
  for (long long i = 1; i <= N; i++) cin >> x[i] >> v[i];
  pair<long long, long long> right[100002], left[100002], rb[100002],
      lb[100002];
  right[0] = rb[0] = make_pair(0, 0);
  left[N + 1] = lb[N + 1] = make_pair(0, 0);
  for (long long i = 1; i <= N + 1; i++) {
    right[i] = make_pair(right[i - 1].first + v[i] - (x[i] - x[i - 1]), i);
    rb[i] = make_pair(right[i - 1].first + v[i] - (x[i] - x[i - 1]) - x[i], i);
  }
  for (long long i = N; i >= 0; i--) {
    left[i] = make_pair(left[i + 1].first + v[i] - (x[i + 1] - x[i]), i);
    lb[i] =
        make_pair(left[i + 1].first + v[i] - (x[i + 1] - x[i]) - (C - x[i]), i);
  }
  sort(right, right + N + 2, greater<pair<long long, long long>>());
  sort(left, left + N + 2, greater<pair<long long, long long>>());
  long long best = max(right[0].first, left[0].first);
  for (int i = 1; i <= N; i++) {
    if (rb[i].first > 0) {
      for (int j = 0; j <= N + 1; j++) {
        if (left[j].second > rb[i].second) {
          best = max(best, rb[i].first + left[j].first);
          break;
        }
      }
    }
    if (lb[i].first > 0) {
      for (int j = 0; j <= N + 1; j++) {
        if (right[j].second < lb[i].second) {
          best = max(best, lb[i].first + right[j].first);
          break;
        }
      }
    }
  }
  cout << best << endl;
  return 0;
}
