#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
void print(int i) { printf("%d", i); }
void print(long long i);
template <class T>
void PI(T i) {
  print(i);
  puts("");
}
template <class T>
void PIS(T i) {
  print(i);
  printf(" ");
}
template <class T>
void PV(T const &v, int N) {
  for (int i = 0; i < int(N); i++) {
    print(v[i]);
    printf("%c", i == N - 1 ? '\n' : ' ');
  }
}
template <class T>
void PV(T const &v) {
  PV(v, ((int)(v).size()));
}
template <class T, class S>
bool has_bit(T mask, S i) {
  return (mask >> i) & 1;
}
long long shift(int i) { return 1ll << i; }
template <class C>
void mini(C &a4, C b4) {
  a4 = min(a4, b4);
}
template <class C>
void maxi(C &a4, C b4) {
  a4 = max(a4, b4);
}
int popcount(int x) { return __builtin_popcount(x); }
int popcount(long long x) { return __builtin_popcountll(x); }
int main() {
  int N;
  scanf("%d", &N);
  long long C;
  scanf("%lld", &(C));
  vector<long long> x(N);
  vector<int> v(N);
  long long sum = 0;
  long long ans = 0;
  vector<long long> best1(N), best2(N);
  for (int i = 0; i < int(N); i++) {
    scanf("%lld", &(x[i]));
    scanf("%d", &v[i]);
    sum += v[i];
    ans = max(ans, sum - x[i]);
    best1[i] = ans;
  }
  sum = 0;
  ans = 0;
  for (int i = (N)-1; i >= 0; i--) {
    sum += v[i];
    ans = max(ans, sum - (C - x[i]));
    best2[i] = ans;
  }
  sum = 0;
  ans = max(best1.back(), best2.back());
  for (int i = 0; i < int(N); i++) {
    sum += v[i];
    ans = max(ans, sum - 2 * x[i] + (i + 1 < N ? best2[i + 1] : 0));
  }
  sum = 0;
  for (int i = (N)-1; i >= 0; i--) {
    sum += v[i];
    ans = max(ans, sum - 2 * (C - x[i]) + (i - 1 >= 0 ? best1[i - 1] : 0));
  }
  printf("%lld\n", ans);
  return 0;
}
