#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, c;
  cin >> n >> c;
  vector<long long int> x(n);
  vector<long long int> v(n);
  vector<long long int> x2(n);
  for (long long int i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
    x2[i] = c - x[i];
  }
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) {
    long long int ans2 = 0;
    for (long long int j = 0; j <= i; j++) {
      ans2 += v[j];
    }
    ans2 -= x[i];
    ans = max(ans, ans2);
    ans2 -= x[i];
    for (long long int j = n - 1; j > i; j--) {
      ans2 += v[j];
      ans = max(ans, ans2 - x2[j]);
    }
  }
  for (long long int i = n - 1; i >= 0; i--) {
    long long int ans2 = 0;
    for (long long int j = n - 1; j >= i; j--) {
      ans2 += v[j];
    }
    ans2 -= x2[i];
    ans = max(ans, ans2);
    ans2 -= x2[i];
    for (long long int j = 0; j < i; j++) {
      ans2 += v[j];
      ans = max(ans, ans2 - x[j]);
    }
  }
  cout << ans << endl;
  return 0;
}
