#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
long long N;
long long C;
long long x[100010];
long long v[100010];
vector<long long> v1, v2;
long long ans;
long long sum[100010];
int main() {
  cin >> N >> C;
  for (long long i = 1; i < N + 1; i++) {
    cin >> x[i] >> v[i];
    if (x[i] < C / 2)
      v1.push_back(i);
    else
      v2.push_back(i);
  }
  for (long long i = 1; i < N + 1; i++) {
    sum[i] = sum[i - 1] + v[i];
  }
  for (long long i = 1; i < N + 1; i++) {
    ans = max({ans, sum[i] - x[i], sum[N] - sum[i - 1] - (C - x[i])});
  }
  long long mx = 0;
  long long ind = 0;
  long long next = 0;
  for (long long i = 1; i < N + 1; i++) {
    if (x[i] > C / 2) {
      next = i;
      break;
    }
    if (mx < sum[i] - x[i]) {
      mx = sum[i] - x[i];
      ind = i;
    }
  }
  long long mx2 = 0;
  long long ind2 = 0;
  for (long long i = next; i < N + 1; i++) {
    if (mx2 < sum[N] - sum[i - 1] - (C - x[i])) {
      mx2 = sum[N] - sum[i - 1] - (C - x[i]);
      ind2 = i;
    }
  }
  ans = max(ans, mx + mx2 - min(x[ind], C - x[ind2]));
  cout << (ans) << endl;
  return 0;
}
