#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
template <typename T>
inline void uin(T &a, T b) {
  if (b < a) a = b;
}
template <typename T>
inline void uax(T &a, T b) {
  if (b > a) a = b;
}
const long long maxn = 100 * 1000 + 228;
long long x[maxn], v[maxn], pref[maxn], suff[maxn], d1[maxn], d2[maxn];
signed main() {
  ios_base::sync_with_stdio(false);
  long long n, c;
  cin >> n >> c;
  for (long long i = 1; i <= (long long)n; ++i) {
    cin >> x[i] >> v[i];
    d1[i] = x[i];
    d2[i] = c - x[i];
  }
  long long res = 0;
  long long bal = 0;
  for (long long i = n; i > 0; --i) {
    bal += v[i];
    suff[i] = max(suff[i + 1], bal - d2[i]);
  }
  for (long long i = 1; i <= (long long)n; ++i) {
    pref[i] = pref[i - 1] + v[i];
  }
  for (long long p = 0; p <= n; ++p) {
    long long cur = pref[p] - d1[p];
    uax(res, cur);
    cur -= d1[p];
    cur += suff[p + 1];
    uax(res, cur);
  }
  for (long long i = 1; i <= (long long)n / 2; ++i) {
    swap(v[i], v[n - i + 1]);
    swap(x[i], x[n - i + 1]);
    x[i] = c - x[i];
    d1[i] = x[i];
    d2[i] = c - x[i];
  }
  bal = 0;
  for (long long i = n; i > 0; --i) {
    bal += v[i];
    suff[i] = max(suff[i + 1], bal - d2[i]);
  }
  for (long long i = 1; i <= (long long)n; ++i) {
    pref[i] = pref[i - 1] + v[i];
  }
  for (long long p = 0; p <= n; ++p) {
    long long cur = pref[p] - d1[p];
    uax(res, cur);
    cur -= d1[p];
    cur += suff[p + 1];
    uax(res, cur);
  }
  cout << res << "\n";
  return 0;
}
