#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T1, class T2>
ostream& operator<<(ostream& s, pair<T1, T2> P) {
  return s << '<' << P.first << ", " << P.second << '>';
}
template <class T>
ostream& operator<<(ostream& s, vector<T> P) {
  for (int i = 0; i < P.size(); ++i) {
    if (i > 0) {
      s << " ";
    }
    s << P[i];
  }
  return s;
}
template <class T>
ostream& operator<<(ostream& s, vector<vector<T> > P) {
  for (int i = 0; i < P.size(); ++i) {
    s << endl << P[i];
  }
  return s << endl;
}
template <class T>
ostream& operator<<(ostream& s, set<T> P) {
  for (__typeof__((P).begin()) it = (P).begin(); it != (P).end(); ++it) {
    s << "<" << *it << "> ";
  }
  return s << endl;
}
template <class T1, class T2>
ostream& operator<<(ostream& s, map<T1, T2> P) {
  for (__typeof__((P).begin()) it = (P).begin(); it != (P).end(); ++it) {
    s << "<" << it->first << "->" << it->second << "> ";
  }
  return s << endl;
}
const int MAX = 110000;
int n;
long long C;
vector<pair<long long, long long> > x;
long long val1[MAX], val2[MAX];
long long sum1[MAX], sum2[MAX];
int main() {
  while (cin >> n >> C) {
    x.resize(n);
    for (int i = 0; i < n; ++i) cin >> x[i].first >> x[i].second;
    sort(x.begin(), x.end());
    long long res = 0;
    long long sum = 0;
    for (int i = 0; i < n; ++i) {
      sum += x[i].second;
      val1[i] = sum - x[i].first;
      if (i == 0)
        sum1[i] = sum - x[i].first;
      else
        sum1[i] = max(sum1[i - 1], sum - x[i].first);
      chmax(res, sum - x[i].first);
    }
    sum = 0;
    for (int i = n - 1; i >= 0; --i) {
      sum += x[i].second;
      val2[i] = sum - (C - x[i].first);
      if (i == n - 1)
        sum2[i] = sum - (C - x[i].first);
      else
        sum2[i] = max(sum1[i + 1], sum - (C - x[i].first));
      chmax(res, sum - (C - x[i].first));
    }
    for (int i = 0; i < n - 1; ++i) {
      long long a = val1[i];
      long long b = sum2[i + 1] - x[i].first;
      chmax(res, a + b);
    }
    for (int i = n - 1; i > 0; --i) {
      long long a = val2[i];
      long long b = sum1[i - 1] - (C - x[i].first);
      chmax(res, a + b);
    }
    cout << res << endl;
  }
}
