#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
signed main() {
  long long n, c;
  cin >> n >> c;
  long long ans = 0;
  long long left1[10010] = {0};
  long long left2[10010] = {0};
  long long right1[10010] = {0};
  long long right2[10010] = {0};
  vector<pair<long long, long long>> s;
  for (long long i = 0; i < (n); i++) {
    long long x, v;
    cin >> x >> v;
    s.push_back(make_pair(x, v));
  }
  long long wal = s[0].second;
  left1[0] = max(0LL, wal - s[0].first);
  left2[0] = max(0LL, wal - 2 * s[0].first);
  ans = max(ans, left1[0]);
  for (long long i = 1; i < n; i++) {
    wal += s[i].second;
    left1[i] = max(left1[i - 1], wal - s[i].first);
    left2[i] = max(left2[i - 1], wal - 2 * s[i].first);
    ans = max(ans, left1[i]);
  }
  long long war = s[n - 1].second;
  right1[0] = max(0LL, war - c + s[n - 1].first);
  right2[0] = max(0LL, war - 2 * c + 2 * s[n - 1].first);
  ans = max(ans, right1[0]);
  for (long long i = 1; i < n; i++) {
    war += s[n - 1 - i].second;
    right1[i] = max(right1[i - 1], war - c + s[n - 1 - i].first);
    right2[i] = max(right2[i - 1], war - 2 * c + 2 * s[n - 1 - i].first);
    ans = max(ans, right1[i]);
  }
  for (long long i = 0; i <= n - 2; i++) {
    ans = max(ans, left2[i] + right1[n - 2 - i]);
    ans = max(ans, left1[n - 2 - i] + right2[i]);
  }
  cout << ans << endl;
  return 0;
}
