#include <bits/stdc++.h>
using namespace std;
long long ans = 0;
long long di[100010] = {};
long long va[100010] = {};
long long c, n;
void dfs(int now, int right, int left, long long cost) {
  ans = max(ans, cost);
  if (right == left) return;
  int now2 = now;
  long long dist = 0;
  if (now < right)
    dist = di[right] - di[now];
  else
    dist = di[right] + (c - di[now]);
  if (va[right] - dist >= 0)
    dfs(right, right + 1, left + 0, cost + (va[right] - dist));
  if (now < left)
    dist = di[now] + (c - di[left]);
  else
    dist = di[now] - di[left];
  if (va[left] - dist >= 0)
    dfs(left, right, left - 1, cost + (va[left] - dist));
}
int main() {
  bool flag = true;
  cin >> n >> c;
  if (n > 110)
    ;
  else {
    for (int i = 1; i <= n; i++) cin >> di[i] >> va[i];
    di[0] = 0;
    va[0] = 0;
    dfs(0, 1, n, 0);
    cout << ans << endl;
  }
  return 0;
}
