#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265358979323846;
pair<long long, long long> m[100000];
vector<pair<long long, long long>> pos1;
vector<pair<long long, long long>> pos2;
int main() {
  long long n;
  scanf("%lld", &n);
  ;
  long long c;
  scanf("%lld", &c);
  ;
  long long s1 = 0, s2 = 0, mx1 = 0, mx2 = 0, t = 0;
  long long s3 = 0, s4 = 0, mx3 = 0, mx4 = 0;
  for (int i = 0; i < n; ++i) {
    long long x;
    scanf("%lld", &x);
    ;
    long long v;
    scanf("%lld", &v);
    ;
    s1 += v - (x - t);
    if (s1 > mx1) {
      mx1 = s1, pos1.push_back(make_pair(i, s1));
    }
    m[i] = make_pair(x, v);
    t = x;
  }
  t = 0;
  for (int i = n - 1; i >= 0; i--) {
    s2 += m[i].second - (c - m[i].first - t);
    if (s2 > mx2) {
      mx2 = s2, pos2.push_back(make_pair(i, s2));
    }
    t = c - m[i].first;
  }
  if (!pos1.empty() && !pos2.empty()) {
    for (auto it = pos1.begin(); it != pos1.end(); ++it) {
      for (auto itt = pos2.rbegin(); itt != pos2.rend(); ++itt) {
        if ((*itt).first > (*it).first) {
          s3 = (*it).second + (*itt).second - m[(*it).first].first;
          break;
        }
      }
      if (s3 > mx3) mx3 = s3;
    }
    for (auto it = pos2.begin(); it != pos2.end(); ++it) {
      for (auto itt = pos1.rbegin(); itt != pos1.rend(); ++itt) {
        if ((*itt).first < (*it).first) {
          s4 = (*it).second + (*itt).second - (c - m[(*it).first].first);
          break;
        }
      }
      if (s4 > mx4) mx4 = s4;
    }
  }
  long long tt = max(mx3, mx4);
  std::cout << max(0ll, (max(max(mx1, mx2), tt)));
}
