#include <bits/stdc++.h>
using namespace std;
long long n, C, x[100005], v[100005], s1[100005], f1[100005], g1[100005],
    f2[100005], g2[100005], s2[100005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> C;
  f1[0] = g1[0] = -1000000000000000007ll;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> v[i];
    s1[i] = s1[i - 1] + v[i];
    f1[i] = s1[i] - x[i];
    g1[i] = s1[i] - 2 * x[i];
    f1[i] = max(f1[i], f1[i - 1]);
    g1[i] = max(g1[i], g1[i - 1]);
  }
  f2[n + 1] = g2[n + 1] = -1000000000000000007ll;
  for (int i = n; i >= 1; i--) {
    s2[i] = s2[i + 1] + v[i];
    f2[i] = max(s2[i] - (C - x[i]), f2[i + 1]);
    g2[i] = max(s2[i] - 2 * (C - x[i]), g2[i + 1]);
  }
  long long res = 0;
  for (int i = 1; i < n; i++) {
    long long ans =
        max({f1[i] + g2[i + 1], g1[i] + f2[i + 1], f1[i], f2[i + 1]});
    res = max(res, ans);
  }
  cout << res;
}
