#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, c;
  cin >> n >> c;
  pair<long long, long long> mp[n];
  for (int i = 0; i < n; i++) {
    cin >> mp[i].first >> mp[i].second;
  }
  long long ans = 0;
  long long amt = 0;
  long long rec1[n], rec2[n];
  long long sum1[n], sum2[n];
  for (int i = 0; i < n; i++) {
    amt += mp[i].second;
    rec1[i] = amt - mp[i].first;
    sum1[i] = amt;
    ans = max(ans, rec1[i]);
  }
  amt = 0;
  for (int i = 0; i < n; i++) {
    amt += mp[n - 1 - i].second;
    rec2[i] = amt - (c - mp[n - 1 - i].first);
    sum2[i] = amt;
    ans = max(ans, rec2[i]);
  }
  for (int i = 1; i < n; i++) {
    rec1[i] = max(rec1[i], rec1[i - 1]);
    rec2[i] = max(rec2[i], rec2[i - i]);
  }
  for (int i = 0; i < n - 1; i++) {
    ans = max(ans, sum1[i] - mp[i].first * 2 + rec2[n - i - 2]);
  }
  for (int i = 0; i < n - 1; i++) {
    ans = max(ans, sum2[i] - (c - mp[n - i - 1].first) * 2 + rec1[n - i - 2]);
  }
  cout << ans << endl;
  return 0;
}
