#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9 + 7;
const long long LINF = 1e18;
using namespace std;
void CINT() {}
template <class Head, class... Tail>
void CINT(Head&& head, Tail&&... tail) {
  cin >> head;
  CINT(move(tail)...);
}
template <class T = long long>
T IN() {
  T x;
  cin >> x;
  return (x);
}
template <class Head>
void VT(Head head) {}
template <class Head, class Seco, class... Tail>
void VT(Head&& head, Seco&& seco, Tail&&... tail) {
  seco.resize(head);
  VT(head, move(tail)...);
}
void VT2() {}
template <class Head, class... Tail>
void VT2(Head&& head, Tail&&... tail) {
  for (auto& youso_ : (head)) cin >> youso_;
  VT2(move(tail)...);
}
template <class Head>
void VT3(Head&& head) {}
template <class Head, class Seco, class... Tail>
void VT3(Head&& head, Seco&& seco, Tail&&... tail) {
  seco[head] = IN();
  VT3(head, move(tail)...);
}
int main() {
  long long n;
  CINT(n);
  long long c;
  CINT(c);
  vector<long long> x, y;
  VT(n, x, y);
  for (int i = 0; i < (n); ++i) VT3(i, x, y);
  ;
  vector<pair<long long, long long> > v1;
  vector<long long> vv1;
  vv1.push_back(0);
  v1.push_back(make_pair(0, 0));
  for (int i = 0; i < (n); ++i) {
    v1.push_back(make_pair(x[i], v1.back().second + y[i]));
    vv1.push_back(v1.back().second - v1.back().first);
  }
  vector<pair<long long, long long> > v2;
  vector<long long> vv2;
  vv2.push_back(0);
  v2.push_back(make_pair(0, 0));
  for (int i = n - 1; i >= 0; i--) {
    v2.push_back(make_pair(c - x[i], v2.back().second + y[i]));
    vv2.push_back(v2.back().second - v2.back().first);
  }
  long long ans = *max_element((vv1).begin(), (vv1).end());
  ans = max(ans, *max_element((vv2).begin(), (vv2).end()));
  for (int i = 0; i < (vv1.size()); ++i) {
    long long val = v1[i].second - (2 * v1[i].first);
    long long index = v2.size() - i;
    long long num = *max_element(vv2.begin(), vv2.begin() + index);
    ans = max(val + num, ans);
  }
  for (int i = 0; i < (vv2.size()); ++i) {
    long long val = v2[i].second - (2 * v2[i].first);
    long long index = v1.size() - i;
    long long num = *max_element(vv1.begin(), vv1.begin() + index);
    ans = max(val + num, ans);
  }
  cout << (ans) << endl;
  return 0;
}
