#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];
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];
  }
  for (long long i = 1; i <= (long long)n; ++i) {
    pref[i] = pref[i - 1] + v[i];
  }
  for (long long i = n; i > 0; --i) {
    suff[i] = suff[i + 1] + v[i];
  }
  long long res = 0;
  for (long long p = 0; p <= n; ++p) {
    for (long long s = 0; p + s <= n; ++s) {
      long long val = pref[p] + suff[n - s + 1];
      long long d1 = 0;
      long long d2 = 0;
      if (p) {
        d1 = x[p];
      }
      if (s) {
        d2 = (c - x[n - s + 1]);
      }
      val -= (d1 + d2 + min(d1, d2));
      uax(res, val);
    }
  }
  cout << res << "\n";
  return 0;
}
