#include <bits/stdc++.h>
using namespace std;
const int mxn = 1e5 + 1;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    long long n, cost, x, ans = 0, i;
    cin >> n >> cost;
    pair<long long, long long> arr[n], arr2[n];
    for (i = 0; i < n; i++) {
      cin >> arr[i].first >> arr[i].second;
    }
    long long mx = 0, temp = 0, pos = 0;
    pair<long long, long long> c[n], ac[n];
    for (i = 0; i < n; i++) {
      arr2[i].first = cost - arr[i].first;
      arr2[i].second = arr[i].second;
      temp += arr[i].second;
      if (mx < temp - arr[i].first) {
        mx = temp - arr[i].first;
        pos = arr[i].first;
      }
      c[i].first = mx;
      c[i].second = pos;
    }
    ans = max(ans, mx);
    mx = 0, temp = 0, pos = 0;
    for (i = n - 1; i >= 0; i--) {
      temp += arr2[i].second;
      if (mx < temp - arr2[i].first) {
        mx = temp - arr2[i].first;
        pos = arr2[i].first;
      }
      ac[i].first = mx;
      ac[i].second = pos;
    }
    ans = max(ans, mx);
    temp = 0;
    for (i = 0; i < n - 1; i++) {
      temp += arr[i].second;
      long long temp2 =
          temp + ac[i + 1].first - arr[i].first - ac[i + 1].second;
      ans = max(ans, temp2);
    }
    temp = 0;
    for (i = n - 1; i > 0; i--) {
      temp += arr2[i].second;
      long long temp2 = temp + c[i - 1].first - arr2[i].first - c[i - 1].second;
      ans = max(ans, temp2);
    }
    cout << ans;
  }
  return 0;
}
