#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  long long C;
  cin >> N >> C;
  vector<long long> X(N), V(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i] >> V[i];
  }
  vector<long long> B(N), B2(N), rB(N), rB2(N);
  {
    long long sum = 0;
    for (int i = 0; i < N; i++) {
      sum += V[i];
      B[i] = sum - X[i];
      B2[i] = sum - 2 * X[i];
    }
  }
  {
    long long sum = 0;
    for (int i = N - 1; i >= 0; i--) {
      sum += V[i];
      rB[i] = sum - (C - X[i]);
      rB2[i] = sum - 2 * (C - X[i]);
      cout << rB[i] << " " << rB2[i] << endl;
    }
  }
  long long ans = 0;
  {
    long long maxi = 0;
    int index = -1;
    for (int i = 0; i < N; i++) {
      if (maxi < B[i]) {
        maxi = B[i];
        index = i;
      }
    }
    if (index != -1) {
      long long reverseMaxi = 0;
      for (int i = N - 1; i > index; i--) {
        reverseMaxi = max(reverseMaxi, rB2[i]);
      }
      ans = max(ans, maxi + reverseMaxi);
    }
  }
  cout << ans << endl;
  {
    long long maxi = 0;
    int index = -1;
    for (int i = N - 1; i >= 0; i--) {
      if (maxi < rB[i]) {
        maxi = rB[i];
        index = i;
      }
    }
    if (index != -1) {
      long long reverseMaxi = 0;
      for (int i = 0; i < index; i++) {
        reverseMaxi = max(reverseMaxi, B2[i]);
      }
      ans = max(ans, maxi + reverseMaxi);
    }
  }
  cout << ans << endl;
  return 0;
}
