#include <bits/stdc++.h>
using namespace std;
const long long MAX_10p5 = 100010;
const long long MAX_10p9 = 1000000010;
const long long MAX_10p18 = 1000000000000000010;
const long long MOD = 1000000007;
const long long m4x[4] = {1, 0, -1, 0};
const long long m4y[4] = {0, 1, 0, -1};
const long long m8x[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long m8y[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long m9x[9] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long m9y[9] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
struct edge {
  long long from, to, cost;
  bool operator<(const edge& right) const { return cost < right.cost; }
};
struct point {
  long long x, y;
  bool operator<(const point& right) const {
    return x == right.x ? y < right.y : x < right.x;
  }
};
long long N, C, ans;
long long x[MAX_10p5], v[MAX_10p5];
long long vsumR[MAX_10p5], vsumL[MAX_10p5];
long long sumR[MAX_10p5], sumL[MAX_10p5], sumRR[MAX_10p5], sumRL[MAX_10p5],
    maxRR[MAX_10p5], maxRL[MAX_10p5];
int main() {
  cin >> N >> C;
  for (long long i = (long long)(0); i < (long long)(N); i++) {
    cin >> x[i] >> v[i];
  }
  for (long long i = (long long)(0); i < (long long)(N); i++) {
    if (i == 0) {
      vsumR[0] = v[i];
      vsumL[0] = v[N - 1];
    } else {
      vsumR[i] = vsumR[i - 1] + v[i];
      vsumL[i] = vsumL[i - 1] + v[N - 1 - i];
    }
  }
  for (long long i = (long long)(0); i < (long long)(N); i++) {
    sumRR[i] = vsumR[i] - x[i] * 2;
    sumRL[i] = vsumL[i] - (C - x[N - 1 - i]) * 2;
  }
  for (long long i = (long long)(0); i < (long long)(N); i++) {
    if (i == 0) {
      maxRR[0] = max(0LL, sumRR[0]);
      maxRL[0] = max(0LL, sumRL[0]);
    } else {
      maxRR[i] = max(maxRR[i - 1], sumRR[i]);
      maxRL[i] = max(maxRL[i - 1], sumRL[i]);
    }
  }
  for (long long i = (long long)(0); i < (long long)(N); i++) {
    if (i != N - 1) {
      ans = max(ans, (vsumR[i] - x[i]) + maxRL[N - 1 - i - 1]);
      ans = max(ans, (vsumL[i] - (C - x[N - 1 - i])) + maxRR[N - 1 - i - 1]);
    } else {
      ans = max(ans, vsumR[i] - x[i] * 2);
      ans = max(ans, vsumL[i] - (C - x[N - 1 - i]) * 2);
    }
  }
  ans = max(ans, vsumR[N - 1] - C);
  cout << ans << endl;
  return 0;
}
