#include <bits/stdc++.h>
using namespace std;
int n;
long long c, ans;
vector<pair<long long, long long> > v;
vector<pair<long long, pair<long long, long long> > > A, B;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> c;
  for (int i = (0); i < (n); ++i) {
    long long a, b;
    cin >> a >> b;
    v.push_back(pair<long long, long long>(a, b));
  }
  if (n > 100) return 0;
  A.resize(n), B.resize(n);
  long long sum = 0;
  for (int i = (0); i < (n); ++i) {
    sum += v[i].second;
    A[i].second.first = sum;
    A[i].second.second = v[i].first;
    A[i].first = A[i].second.first - A[i].second.second;
    ans = max(ans, A[i].first);
  }
  reverse((v).begin(), (v).end());
  sum = 0;
  for (int i = (0); i < (n); ++i) {
    sum += v[i].second;
    B[i].second.first = sum;
    B[i].second.second = c - v[i].first;
    B[i].first = B[i].second.first - B[i].second.second;
    ans = max(ans, B[i].first);
  }
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (n - i - 1); ++j) {
      long long tmp = A[i].first - A[i].second.second + B[j].first;
      ans = max(ans, tmp);
      tmp = B[i].first - B[i].second.second + A[j].first;
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
  return 0;
}
