#include <bits/stdc++.h>
using namespace std;
long long int x[100005];
long long int v[100005];
long long int n, c;
int main() {
  cin >> n >> c;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
  }
  long long int ans = 0;
  long long int cals = 0;
  for (int i = 0; i < n; i++) {
    cals += v[i];
    ans = max(ans, cals - x[i]);
  }
  cals = 0;
  for (int i = n - 1; i >= 0; i--) {
    cals += v[i];
    ans = max(ans, cals - (c - x[i]));
  }
  for (int i = 0; i < n; i++) {
    for (int j = n - 1; j > i; j--) {
      long long int cals = 0;
      for (int k = 0; k <= i; k++) {
        cals += v[k];
      }
      for (int k = n - 1; k >= j; k--) {
        cals += v[k];
      }
      long long int dist = min(2 * x[i] + c - x[j], 2 * (c - x[j]) + x[i]);
      ans = max(ans, cals - dist);
    }
  }
  cout << ans;
}
