#include <bits/stdc++.h>
using namespace std;
const int INF = (long long int)(1LL << 30) - 1;
const double INFd = 100000000000.0;
const long long int INFl = (long long int)9223372036854775807;
const int MAX = 10000;
const long long int MOD = (long long int)1e9 + 7;
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
long long int lcm(long long int a, long long int b) {
  return a / gcd(a, b) * b;
}
int dx[4] = {0, -1, 0, 1}, dy[4] = {-1, 0, 1, 0};
int mdx[8] = {0, 1, 0, -1, 1, 1, -1, -1}, mdy[8] = {-1, 0, 1, 0, 1, -1, 1, -1};
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
long long int n, c;
long long int x[100100];
long long int v[100100];
long long int cx[100100];
long long int c2x[100100];
long long int c_cx[100100];
long long int c_c2x[100100];
long long int mcx[100100];
long long int mc2x[100100];
long long int mc_cx[100100];
long long int mc_c2x[100100];
int main() {
  cin >> n >> c;
  for (long long int i = 1; i < n + 1; i++) cin >> x[i] >> v[i];
  long long int sum = 0;
  for (long long int i = 1; i < n + 1; i++) {
    sum += v[i];
    cx[i] = sum - x[i];
    c2x[i] = sum - 2 * x[i];
  }
  sum = 0;
  for (int i = n; i >= 1; i--) {
    sum += v[i];
    c_cx[i] = sum - (c - x[i]);
    c_c2x[i] = sum - 2 * (c - x[i]);
  }
  for (long long int i = 1; i < n + 1; i++) {
    mcx[i] = ((mcx[i - 1]) > (cx[i]) ? (mcx[i - 1]) : (cx[i]));
    mc2x[i] = ((mc2x[i - 1]) > (c2x[i]) ? (mc2x[i - 1]) : (c2x[i]));
  }
  for (int i = n; i >= 1; i--) {
    mc_cx[i] = ((mc_cx[i + 1]) > (c_cx[i]) ? (mc_cx[i + 1]) : (c_cx[i]));
    mc_c2x[i] = ((mc_c2x[i + 1]) > (c_c2x[i]) ? (mc_c2x[i + 1]) : (c_c2x[i]));
  }
  long long int ans = 0;
  for (int i = 0; i <= n; i++) {
    ans = ((ans) > (mcx[i + 1] + mc_c2x[i]) ? (ans) : (mcx[i + 1] + mc_c2x[i]));
  }
  for (int i = 0; i <= n; i++) {
    ans = ((ans) > (mc2x[i] + mc_cx[i + 1]) ? (ans) : (mc2x[i] + mc_cx[i + 1]));
  }
  cout << ans << endl;
  return 0;
}
