#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& a) {
  return os << "(" << a.first << "," << a.second << ")";
}
template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << (*i) << " ";
  cout << endl;
}
template <class T>
void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
int nextInt() {
  int x;
  scanf("%d", &x);
  return x;
}
long long nextLong() {
  long long x;
  scanf("%lld", &x);
  return x;
}
const int MAX_N = 112345;
const long long INF = 1LL << 58;
struct BITMAX {
  int n;
  long long vs[MAX_N + 1];
  BITMAX() {
    this->n = MAX_N;
    clear();
  }
  void clear() {
    for (int i = 0, _n = (int)(n + 1); i < _n; ++i) vs[i] = -INF;
  }
  void update(int idx, long long val) {
    for (int x = idx + 1; x <= n; x += x & -x) vs[x] = max(vs[x], val);
  }
  long long get(int idx) {
    long long val = -INF;
    for (int x = idx + 1; x > 0; x -= x & -x) val = max(val, vs[x]);
    return val;
  }
};
long long X[MAX_N], V[MAX_N];
BITMAX bit;
long long solve(int N, long long C) {
  vector<long long> a(N + 1);
  for (int i = 0, _n = (int)(N); i < _n; ++i) a[i + 1] = a[i] + (V[i]);
  for (int i = 0, _n = (int)(N); i < _n; ++i) a[i + 1] -= X[i];
  bit.clear();
  for (int i = 0, _n = (int)(N); i < _n; ++i) bit.update(i, a[i]);
  long long best = bit.get(N);
  long long get = 0;
  for (int b = N - 1; b >= 0; b--) {
    get += V[b];
    long long score = get - (C - X[b]) * 2;
    score += bit.get(b);
    chmax(best, score);
  }
  return best;
}
int main2() {
  int N = nextInt();
  long long C = nextLong();
  for (int i = 0, _n = (int)(N); i < _n; ++i) {
    X[i] = nextLong();
    V[i] = nextLong();
  }
  long long ans1 = solve(N, C);
  reverse(X, X + N);
  reverse(V, V + N);
  for (int i = 0, _n = (int)(N); i < _n; ++i) X[i] = C - X[i];
  long long ans2 = solve(N, C);
  long long ans = max(ans1, ans2);
  cout << ans << endl;
  return 0;
}
int main() {
  for (; !cin.eof(); cin >> ws) main2();
  return 0;
}
