#include <bits/stdc++.h>
using namespace std;
long long inf = 2147483647;
const long long ll = 9223372036854775807, ninf = 1000000000;
const double eps = 1e-6;
const long long nll = 1000000000000000000;
class MinimizeAbsoluteDifferenceDiv1 {
 public:
  vector<int> findTuple(vector<int> x) {}
};
int main() {
  int a, b;
  while (cin >> a >> b) {
    int w[100005] = {};
    int w1[100005] = {};
    int x[100005] = {};
    for (int i = 1; i <= a; i++) {
      cin >> x[i] >> w[i];
    }
    for (int i = 1; i <= a; i++) w[i] = w[i - 1] + w[i];
    int t1[100005] = {};
    int t2[100005] = {};
    int ans = 0;
    for (int i = 1; i <= a; i++) {
      w[i] = w[i] - x[i];
      w1[i] = w[a] - w[i - 1] - (b - x[i]);
      t1[i] = w[i] - x[i];
      t2[i] = w1[i] - (b - x[i]);
      ans = max(ans, w1[i]);
      ans = max(ans, w[i]);
    }
    int num = 0;
    for (int i = 1; i <= a; i++) {
      ans = max(ans, num + w1[i]);
      num = max(num, t1[i]);
    }
    num = 0;
    for (int i = a; i >= 1; i--) {
      ans = max(ans, num + w[i]);
      num = max(num, t2[i]);
    }
    cout << ans << '\n';
  }
  return 0;
}
