#include <bits/stdc++.h>
using namespace std;
long long dp_r[100005], dp_l[100005];
long long dp_rb[100005], dp_lb[100005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long N, C;
  cin >> N >> C;
  long long x1[N], x2[N], v1[N], v2[N];
  for (int i = (0); i < (N); ++i) cin >> x1[i] >> v1[i];
  for (int i = (0); i < (N); ++i) x2[i] = C - x1[N - i - 1];
  for (int i = (0); i < (N); ++i) v2[i] = v1[N - i - 1];
  long long ans = 0;
  long long now = 0;
  for (int i = (0); i < (N); ++i) {
    now += v1[i];
    dp_l[i + 1] = max(dp_l[i], now - x1[i]);
    dp_lb[i + 1] = max(dp_lb[i], now - 2 * x1[i]);
    cout << dp_l[i + 1] << endl;
    cout << dp_lb[i + 1] << endl;
  }
  now = 0;
  for (int i = (0); i < (N); ++i) {
    now += v2[i];
    dp_r[i + 1] = max(dp_r[i], now - x2[i]);
    dp_rb[i + 1] = max(dp_rb[i], now - 2 * x2[i]);
    cout << dp_r[i + 1] << endl;
    cout << dp_rb[i + 1] << endl;
  }
  for (int i = (0); i < (N + 1); ++i) {
    ans = max(ans, max(dp_l[i], dp_r[N - i]));
    ans = max(ans, dp_lb[i] + dp_r[N - i]);
    ans = max(ans, dp_l[i] + dp_rb[N - i]);
  }
  cout << ans << endl;
}
