#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;
template <typename T>
void say(T s) {
  cout << s << "\n";
}
template <typename T>
void say(vector<T> s) {
  auto itr = s.begin();
  cout << *(itr++);
  while (itr != s.end()) {
    cout << " " << *(itr++);
  }
  cout << "\n";
}
void yn(bool b) {
  if (b)
    say("Yes");
  else
    say("No");
}
template <typename T>
void maxi(T &a, T b) {
  a = max(a, b);
}
template <typename T>
void mini(T &a, T b) {
  a = min(a, b);
}
int main() {
  ll ans = 0;
  ll sum = 0;
  ll rsum = 0;
  vll a, r;
  int N;
  cin >> N;
  ;
  ll C;
  cin >> C;
  ;
  vll x(N), v(N);
  for (int i = 0; i < N; ++i) cin >> x[i] >> v[i];
  for (int i = 0; i < N; ++i) {
    sum += v[i];
    rsum += v[N - 1 - i];
    ans = max(ans, sum - x[i]);
    ans = max(ans, rsum - C + x[N - 1 - i]);
    a.push_back(sum);
    r.push_back(rsum);
  }
  for (int i = 0; i < N - 1; ++i) {
    for (int j = 0; j < N - 1 - i; ++j) {
      ans = max(ans, a[i] + r[j] - 2 * x[i] - (C - x[N - 1 - j]));
      ans = max(ans, a[i] + r[j] - x[i] - 2 * (C - x[N - 1 - j]));
    }
  }
  say(ans);
}
