#include <bits/stdc++.h>
using namespace std;
long long x[100010], v[100010];
long long sum1[100010], sum2[100010];
long long ma1[100010], ma2[100010];
int main() {
  int N;
  long long C;
  cin >> N >> C;
  for (int i = 1; i <= N; i++) cin >> x[i] >> v[i];
  x[N + 1] = C;
  for (int i = 1; i <= N; i++) {
    sum1[i] = sum1[i - 1] + v[i];
    ma1[i] = sum1[i] - x[i];
    sum2[i] = sum2[i + 1] + v[i];
    ma2[i] = sum2[i] - (C - x[i]);
  }
  long long ans = 0;
  for (int i = 1; i <= N; i++)
    ma1[i] = max(ma1[i], ma1[i - 1]), ans = max(ans, ma1[i]);
  for (int i = N; i >= 1; i--)
    ma2[i] = max(ma2[i], ma2[i + 1]), ans = max(ans, ma2[i]);
  for (int i = 1; i <= N; i++) {
    ans = max(ans, ma1[i] + ma2[i + 1] - min(x[i], C - x[i + 1]));
  }
  cout << ans << endl;
}
