#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  unsigned long long C;
  cin >> N;
  cin >> C;
  int x[N];
  long v[N];
  for (int i = 0; i < N; i++) {
    cin >> x[i];
    cin >> v[i];
  }
  int max1 = 0;
  unsigned long long score1 = 0;
  unsigned long long maxLoc1 = 0;
  for (int i = 0; i < N; i++) {
    int distance;
    if (i == 0) {
      distance = x[0];
    } else {
      distance = x[i] - x[i - 1];
    }
    score1 = score1 + v[i] - distance;
    if (score1 > max1) {
      max1 = score1;
      maxLoc1 = x[i];
    }
  }
  int max2 = 0;
  unsigned long long score2 = 0;
  unsigned long long maxLoc2 = 0;
  for (int i = N - 1; i > -1; i--) {
    int distance;
    if (i == N - 1) {
      distance = C - x[N - 1];
    } else {
      distance = x[i + 1] - x[i];
    }
    score2 = score2 + v[i] - distance;
    if (score2 > max2) {
      max2 = score2;
      maxLoc2 = x[i];
    }
  }
  int max3 = max2;
  unsigned long long score3 = score2;
  cout << maxLoc2 << endl;
  for (int i = 0; i < N - 1; i++) {
    if (x[i] * 2 > maxLoc2) {
      break;
    }
    int distance;
    if (i == 0) {
      distance = x[0];
    } else {
      distance = x[i] - x[i - 1];
    }
    score3 = score3 + v[i] - 2 * distance;
    if (score3 > max3) {
      max3 = score3;
    }
  }
  int max4 = max1;
  unsigned long long score4 = score1;
  for (int i = N - 1; i > -1; i--) {
    if ((C - x[i]) * 2 + maxLoc1 > C) {
      break;
    }
    int distance;
    if (i == N - 1) {
      distance = C - x[N - 1];
    } else {
      distance = x[i + 1] - x[i];
    }
    score4 = score4 + v[i] - 2 * distance;
    if (score4 > max4) {
      max4 = score4;
    }
  }
  int max = 0;
  if (max3 > max4) {
    max = max3;
  } else {
    max = max4;
  }
  cout << max << endl;
  return 0;
}
