#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const int INF = (1 << 30);
long long N, C;
vector<pair<long long, long long>> xv;
void input() {
  cin >> N >> C;
  for (int((i)) = (0); ((i)) < ((N)); ((i))++) {
    long long a, b;
    cin >> a >> b;
    xv.push_back({a, b});
  }
}
void calc() {
  vector<long long> nor1(1, 0), nor2(1, 0), rev1(1, 0), rev2(1, 0);
  for (int((i)) = (0); ((i)) < ((N)); ((i))++) {
    nor1.push_back(nor1.back() + xv[i].second);
    ;
    nor2.push_back(nor2.back() + xv[i].second);
    rev1.push_back(rev1.back() + xv[N - i - 1].second);
    rev2.push_back(rev2.back() + xv[N - i - 1].second);
  }
  for (int((i)) = (0); ((i)) < ((N)); ((i))++) {
    nor1[i + 1] -= xv[i].first;
    nor2[i + 1] -= xv[i].first * 2;
    rev1[i + 1] -= (C - xv[N - i - 1].first);
    rev2[i + 1] -= (C - xv[N - i - 1].first) * 2;
  }
  long long ans = 0;
  for (int((i)) = (0); ((i)) < ((N + 1)); ((i))++) {
    long long tmpS = rev2[i];
    tmpS += *max_element(nor1.begin(), nor1.end() - i);
    ans = max(ans, tmpS);
  }
  for (int((i)) = (0); ((i)) < ((N + 1)); ((i))++) {
    long long tmpS = nor2[i];
    tmpS += *max_element(rev1.begin(), rev1.end() - i);
    ans = max(ans, tmpS);
  }
  cout << max(ans, 0ll) << endl;
}
void output() {}
void debug() {
  int N;
  cin >> N;
}
int main() {
  input();
  calc();
  output();
  debug();
  return 0;
}
