#include <bits/stdc++.h>
using namespace std;
long long int max(vector<long long int> v) {
  long long int temp = 0;
  for (auto e : v) {
    temp = max(e, temp);
  }
  return temp;
}
int main() {
  int n;
  long long int c;
  cin >> n >> c;
  vector<pair<long long int, int>> sushis(n + 1);
  sushis[0] = {0, 0};
  for (int i = 1; i <= n; i++) {
    long long int x;
    int v;
    cin >> x >> v;
    sushis[i] = {x, v};
  }
  long long int max_cal = 0;
  for (int k = 0; k <= n; k++) {
    vector<long long int> process;
    process.push_back(0);
    for (int i = 0; i <= n; i++) {
      if (i != 0) {
        long long int temp = process.back();
        long long int cal =
            sushis[i].second - (sushis[i].first - sushis[i - 1].first);
        process.push_back(temp + cal);
      }
      vector<long long int> process_back;
      process_back.push_back(process.back());
      for (int j = n; j > i; j--) {
        long long int temp = process_back.back();
        if (j == n) {
          long long int cal =
              sushis[j].second - (c - (sushis[j].first - sushis[i].first));
          process_back.push_back(temp + cal);
        } else {
          long long int cal =
              sushis[j].second - (sushis[j + 1].first - sushis[j].first);
          process_back.push_back(temp + cal);
        }
      }
      long long int max_local_back = max(process_back);
      max_cal = max(max_cal, max_local_back);
    }
    long long int max_local = max(process);
    max_cal = max(max_cal, max_local);
  }
  cout << max_cal << endl;
  return 0;
}
