#include <bits/stdc++.h>
using namespace std;
const long long INF =
    sizeof(long long) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const long long MOD = (long long)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  long long N, C;
  cin >> N >> C;
  vector<long long> x(N + 1), v(N + 1);
  for (long long i = (1); i < (N + 1); i++) {
    cin >> x[i] >> v[i];
  }
  vector<long long> y(N + 1), w(v);
  for (long long i = (1); i < (N + 1); i++) {
    y[i] = C - y[i];
  }
  for (long long i = (1); i < (N + 1); i++) {
    v[i] += v[i - 1];
  }
  for (long long i = (N + 1) - 1; i >= (1); i--) {
    w[i - 1] += w[i];
  }
  w[0] = 0;
  ;
  ;
  long long ans = 0;
  for (long long i = (0); i < (N + 1); i++) {
    for (long long j = (i + 1); j < (N + 1); j++) {
      ;
      long long score = v[i] - x[i] + w[j] - (C - x[j]) - min(x[i], C - x[j]);
      ;
      chmax(ans, score);
      if (j == N) {
        score = v[i] - x[i];
        ;
        chmax(ans, score);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
