#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long int n, c;
  cin >> n >> c;
  vector<long long int> x;
  vector<long long int> v;
  long long int inp1, inp2;
  x.push_back(0);
  v.push_back(0);
  for (long long int i = 0; i < n; i++) {
    cin >> inp1 >> inp2;
    x.push_back(inp1);
    v.push_back(inp2);
  }
  x.push_back(c);
  v.push_back(0);
  long long int sol = 0;
  long long int profit;
  long long int sl = 0;
  long long int sr;
  for (long long int i = 0; i <= n; i++) {
    sl += v[i];
    sr = 0;
    for (long long int j = n + 1; j > i; j--) {
      sr += v[j];
      profit = sl + sr - x[i] - (c - x[j]) - min(x[i], c - x[j]);
      sol = max(sol, profit);
    }
  }
  cout << sol << endl;
}
