#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int N;
long long C, X[101010], V[101010], sum1[101010], sum2[101010];
int main() {
  cin >> N >> C;
  for (int i = 0; i < (N); i++) cin >> X[i] >> V[i];
  long long ans = 0;
  for (int i = 0; i < (N); i++) {
    sum1[i + 1] = sum1[i] + V[i];
    sum2[i + 1] = sum2[i] + V[N - 1 - i];
    ans = max(ans, sum1[i + 1] - X[i]);
    ans = max(ans, sum2[i + 1] - (C - X[N - 1 - i]));
  }
  for (int i = 0; i < (N); i++) {
    long long tmp = sum1[i + 1] - X[i];
    for (int j = N - 1; j > i; j--) {
      ans = max(ans, tmp - min(X[i], (C - X[j])) + sum2[N - j] - (C - X[j]));
    }
  }
  cout << ans << endl;
  return 0;
}
