#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <class T>
using V = vector<T>;
template <class T>
using VV = vector<vector<T> >;
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
inline ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
inline ll powint(unsigned long long x, ll y) {
  ll r = 1;
  while (y) {
    if (y & 1) r *= x;
    x *= x;
    y >>= 1;
  }
  return r;
}
inline ll powmod(ll x, ll y, ll m = MOD) {
  ll r = 1;
  while (y) {
    if (y & 1) r *= x;
    x *= x;
    r %= m;
    x %= m;
    y >>= 1;
  }
  return r;
}
template <class S, class T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class S, class T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll n, c;
  cin >> n >> c;
  vll x(n), v(n);
  for (ll i = 0; i < (n); i++) {
    cin >> x[i] >> v[i];
  }
  assert(n <= 100);
  ll ld = 0;
  ll rd = 0;
  ll lval = 0;
  ll rval = 0;
  ll ans = 0;
  for (ll i = 0; i < (n); i++) {
    rval += v[i];
    rd = x[i];
    ld = 0;
    lval = 0;
    for (ll j = (n)-1; j >= (i + 1); j--) {
      lval += v[j];
      ld = c - x[j];
      chmax(ans, lval + rval - min(ld * 2 + rd, ld + rd * 2));
    }
  }
  rval = 0;
  rd = 0;
  for (ll i = 0; i < (n); i++) {
    rval += v[i];
    rd = x[i];
    chmax(ans, rval - rd);
  }
  lval = 0;
  ld = 0;
  for (ll i = (n)-1; i >= 0; i--) {
    lval += v[i];
    ld = c - x[i];
    chmax(ans, lval - ld);
  }
  cout << ans << endl;
  return 0;
}
