#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
long long int n, c;
long long int func(vector<long long int> x, vector<int> v) {
  cerr << "func" << endl;
  long long int ans = 0;
  long long int tmp = 0;
  int p = 0;
  for (int i = 0; i < n; i++) {
    tmp += v[i];
    if (i != 0)
      tmp -= (x[i] - x[i - 1]);
    else
      tmp -= x[i];
    if (ans < tmp) {
      ans = tmp;
      p = i;
    }
  }
  cerr << "  " << ans << " " << p << endl;
  tmp = ans;
  for (int i = 0; i < n; i++) {
    if (n - 1 - i == p) break;
    tmp += v[n - 1 - i];
    if (i != 0)
      tmp -= 2 * (x[n - i] - x[n - i - 1]);
    else
      tmp -= 2 * (c - x[n - 1]);
    ans = max(tmp, ans);
  }
  cerr << "  " << ans << endl;
  return ans;
}
long long int func2(vector<long long int> x, vector<int> v) {
  long long int ans = 0;
  long long int tmp = 0;
  int p = 0;
  vector<long long int> sum(n, 0);
  for (int i = 0; i < n; i++) {
    tmp += v[n - 1 - i];
    if (i != 0)
      tmp -= (x[n - i] - x[n - i - 1]);
    else
      tmp -= c - x[n - 1];
    sum[n - 1 - i] = tmp;
    cerr << n - 1 - i << " " << sum[n - 1 - i] << endl;
    if (ans < tmp) {
      ans = tmp;
      p = i;
    }
  }
  cerr << "  " << ans << " " << p << endl;
  tmp = 0;
  long long int a = 0;
  for (int i = 0; i < n; i++) {
    tmp += v[i];
    if (i != 0)
      tmp -= 2 * (x[i] - x[i - 1]);
    else
      tmp -= 2 * x[i];
    a = max(a, tmp);
    cerr << a << endl;
    if (a > 0) sum[n - 1 - i] += a;
  }
  for (int i = 0; i < n; i++) cerr << i << " " << sum[i] - v[i] << endl;
  cerr << "  " << ans << endl;
  return ans;
}
long long int funca(vector<long long int> x, vector<int> v) {
  long long int ans = 0;
  long long int tmp = 0;
  int p = 0;
  vector<long long int> sum(n, 0);
  vector<long long int> sum2(n, 0);
  for (int i = 0; i < n; i++) {
    tmp += v[i];
    if (i != 0)
      tmp -= 2 * (x[i] - x[i - 1]);
    else
      tmp -= 2 * x[i];
    ans = max(ans, tmp);
    sum[i] = ans;
  }
  ans = 0;
  tmp = 0;
  for (int i = 0; i < n; i++) {
    tmp += v[n - 1 - i];
    if (i != 0)
      tmp -= (x[n - i] - x[n - i - 1]);
    else
      tmp -= c - x[n - 1];
    ans = max(tmp, ans);
    sum2[i] = ans;
  }
  long long int ret = 0;
  for (int i = 0; i < n - 1; i++) {
    ret = max(sum[i] + sum2[i + 1], ret);
  }
  return ans;
}
int main() {
  cin >> n >> c;
  vector<long long int> x(n);
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
  }
  long long int ans = 0;
  ans = max(ans, funca(x, v));
  reverse(x.begin(), x.end());
  reverse(v.begin(), v.end());
  ans = max(ans, funca(x, v));
  cout << ans << endl;
  return 0;
}
