#include <bits/stdc++.h>
using namespace std;
int n;
long long c;
vector<long long> x, v;
vector<bool> used;
long long memo[2][100010];
long long rec(int k = 0, int prev = -1) {
  if (k == n) {
    return 0;
  }
  long long res = 0;
  int i = 0;
  while (used[i]) {
    i++;
    if (i == n) i = 0;
  }
  used[i] = true;
  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]));
    }
  }
  used[i] = false;
  i = n - 1;
  while (used[i]) {
    i--;
    if (i == -1) i = n - 1;
  }
  used[i] = true;
  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]));
    }
  }
  used[i] = false;
  return res;
}
int main() {
  cin >> n >> c;
  x = v = vector<long long>(n);
  used = vector<bool>(n, false);
  for (int i = (0); i < (n); i++) cin >> x[i] >> v[i];
  cout << rec() << endl;
  return 0;
}
