#include <bits/stdc++.h>
using namespace std;
long long dp[105][105], n, c;
vector<long long> x, v, leftR, rightR, lx, rx;
int main() {
  cin >> n >> c;
  rightR.push_back(0);
  rx.push_back(0);
  for (signed long long i = 0; i < (n); i++) {
    long long a, b;
    cin >> a >> b;
    x.push_back(a);
    v.push_back(b);
    lx.push_back(c - a);
    rx.push_back(a);
    leftR.push_back(b);
    rightR.push_back(b);
  }
  leftR.push_back(0);
  lx.push_back(0);
  for (signed long long i = 0; i < (n); i++) rightR[i + 1] += rightR[i];
  for (long long i = n; i > 0; i--) leftR[i - 1] += leftR[i];
  long long ret = 0;
  for (long long right = 0; right < n; right++) {
    for (long long left = n; left > right; left--) {
      ret = max(ret, rightR[right] + leftR[left] - min(rx[right], lx[left]) -
                         lx[left] - rx[right]);
      if (right == 2 && left == 3) {
        cout << rightR[right] << " " << leftR[left] << endl;
        cout << rightR[right] + leftR[left] - min(rx[right], lx[left]) -
                    lx[left] - rx[right]
             << endl;
      }
    }
  }
  cout << ret << endl;
}
