#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000009;
int n;
long long c;
pair<long long, long long> sus[100010];
long long l[100010] = {}, r[100010] = {};
long long l2[10010] = {}, r2[10010] = {};
int main() {
  cin >> n >> c;
  sus[0] = make_pair(0LL, 0LL);
  sus[n + 1] = make_pair(c, 0LL);
  for (int i = 1; i <= n; i++) {
    long long x, v;
    cin >> x >> v;
    sus[i] = make_pair(x, v);
  }
  long long lans = 0LL, lans2 = 0LL;
  int li = 0;
  sort(sus, sus + n);
  for (int i = 1; i <= n; i++) {
    l[i] = l[i - 1] + sus[i].second - sus[i].first + sus[i - 1].first;
    l2[i] = max(l2[i - 1], l[i] - sus[i].first);
  }
  long long rans = 0LL, rans2 = 0LL;
  int ri = n + 1;
  for (int i = n; i >= 1; i--) {
    r[i] = r[i + 1] + sus[i].second + sus[i].first - sus[i + 1].first;
    r2[i] = max(r2[i + 1], r[i] - c + sus[i].first);
  }
  long long ans;
  for (int i = 0; i <= n; i++) {
    ans = max(ans, l[i] + r2[i + 1]);
    ans = max(ans, r[i] + l2[i - 1]);
  }
  cout << ans << endl;
  return 0;
}
