#include <bits/stdc++.h>
using namespace std;
const int INT_INF = 500000000;
const long long LL_INF = (long long)pow(10, 18);
long long N, C;
long long x[100004] = {0};
long long v[100004] = {0};
long long dp1[100004] = {0};
long long dp2[100004] = {0};
long long dp3[100004] = {0};
long long dp4[100004] = {0};
int main() {
  cin >> N >> C;
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> v[i];
  }
  long long v_0toN = 0;
  long long v_Nto0 = 0;
  for (int i = 0; i < N; i++) {
    v_0toN += v[i];
    v_Nto0 += v[N - i - 1];
    if (dp1[i] >= v_0toN - x[i]) {
      dp1[i + 1] = dp1[i];
      dp3[i + 1] = dp3[i];
    } else {
      dp1[i + 1] = v_0toN - x[i];
      dp3[i + 1] = v_0toN - 2 * x[i];
    }
    int k = v_Nto0 - (C - x[N - i - 1]);
    if (dp2[N - i + 1] < k) {
      dp2[N - i] = k;
      dp4[N - i] = v_Nto0 - 2 * (C - x[N - i - 1]);
    } else {
      dp2[N - i] = dp2[N - i + 1];
      dp4[N - i] = dp4[N - i + 1];
    }
  }
  long long a = 0;
  long long b = 0;
  for (int i = 0; i <= N; i++) {
    a = max(dp4[i + 1] + dp1[i], a);
    b = max(dp3[i] + dp2[i + 1], b);
  }
  cout << max(a, b) << endl;
  return 0;
}
