#include <bits/stdc++.h>
using namespace std;
const int tam = 100002;
long long n, C;
long long dis[tam];
long long nut[tam];
long long suf[tam];
long long pre[tam];
pair<long long, int> mx[tam];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> C;
  long long ans = 0;
  int idx = 0;
  for (int i = 0; i < n; ++i) {
    cin >> dis[i + 1] >> nut[i + 1];
    pre[i + 1] = pre[i] + nut[i + 1] + dis[i] - dis[i + 1];
    if (pre[i + 1] > ans) {
      ans = pre[i + 1];
      idx = i + 1;
    }
    mx[i + 1] = pair<long long, int>(ans, idx);
    cout << i + 1 << " " << ans << " " << idx << '\n';
  }
  dis[n + 1] = C;
  int i;
  for (i = n; i >= 1; --i) {
    suf[i] = suf[i + 1] + nut[i] + (C - dis[i + 1]) - (C - dis[i]);
    ans = max(ans, suf[i]);
  }
  for (i = n; i >= 1; --i) {
    pair<long long, int> res = mx[i - 1];
    long long cost = res.first + suf[i] - min(dis[res.second], C - dis[i]);
    ans = max(ans, cost);
  }
  cout << ans << '\n';
  return 0;
}
