#include <bits/stdc++.h>
using namespace std;
long long n, c, x[100010], v[100010];
long long F() {
  priority_queue<long long> Q;
  long long cnt = 0;
  for (int i = 0; i < n; i++) cnt += v[i];
  cnt -= 2 * (c - x[0]);
  long long ans = cnt;
  long long sum = 0;
  Q.push(0);
  x[n] = c;
  for (int k = 0; k < n; k++) {
    sum += v[k];
    Q.push(sum - x[k]);
    cnt -= v[k];
    cnt += 2 * (x[k + 1] - x[k]);
    ans = max(ans, cnt + Q.top());
  }
  return ans;
}
int main() {
  cin >> n >> c;
  for (int i = 0; i < n; i++) cin >> x[i] >> v[i];
  long long ans = F();
  for (int i = 0; i < n; i++) x[i] = c - x[i];
  sort(x, x + n);
  ans = max(ans, F());
  cout << ans << endl;
  return 0;
}
