#include <bits/stdc++.h>
using namespace std;
int n;
long long c;
vector<long long> x, v;
deque<int> table;
long long memo[2][100010];
long long rec(int k = 0, int prev = -1) {
  if (k == n) return 0;
  if (memo[k][prev + 1] != -1) return memo[k][prev + 1];
  long long res = 0;
  int i = table.front();
  table.pop_front();
  if (prev == -1) {
    res = max(res, rec(k + 1, i) + v[i] - x[i]);
  } else {
    long long tmp = max(res, rec(k + 1, i));
    if (x[i] > x[prev]) {
      res = max(res, tmp + v[i] - (x[i] - x[prev]));
    } else {
      res = max(res, tmp + v[i] - (c - x[prev] + x[i]));
    }
  }
  table.push_front(i);
  i = table.back();
  table.pop_back();
  if (prev == -1) {
    res = max(res, rec(k + 1, i) + v[i] - (c - x[i]));
  } else {
    long long tmp = rec(k + 1, i);
    if (x[i] < x[prev]) {
      res = max(res, tmp + v[i] - (x[prev] - x[i]));
    } else {
      res = max(res, tmp + v[i] - x[prev] - (c - x[i]));
    }
  }
  table.push_back(i);
  return memo[k][prev + 1] = res;
}
int main() {
  cin >> n >> c;
  x = v = vector<long long>(n);
  memset(memo, -1, sizeof(memo));
  for (int i = (0); i < (n); i++) {
    cin >> x[i] >> v[i];
    table.push_back(i);
  }
  cout << rec() << endl;
  return 0;
}
