#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  long long C;
  cin >> N >> C;
  vector<long long> xs(N), vs(N);
  for (int i = 0; i < N; i++) {
    cin >> xs[i] >> vs[i];
  }
  vector<long long> right(N + 1), left(N + 1), right2(N + 1), left2(N + 1);
  {
    long long sum = 0;
    for (int i = 0; i < N; i++) {
      sum += vs[i];
      right[i + 1] = sum - xs[i];
      right2[i + 1] = sum - 2 * xs[i];
    }
  }
  {
    long long sum = 0;
    for (int i = N - 1; i >= 0; i--) {
      sum += vs[i];
      left[i] = sum - (C - xs[i]);
      left2[i] = sum - 2 * (C - xs[i]);
    }
  }
  long long ans = 0;
  {
    long long maxi = 0;
    for (int i = 0; i <= N; i++) {
      ans = max(ans, maxi + left[i]);
      maxi = max(maxi, right2[i]);
    }
  }
  {
    long long maxi = 0;
    for (int i = N; i >= 0; i--) {
      ans = max(ans, maxi + right[i]);
      maxi = max(maxi, left2[i]);
    }
  }
  cout << ans << endl;
  return 0;
}
