#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
struct Sushi {
  long long pos;
  long long cal;
};
Sushi sushi[100000];
long long N, C;
long long distance(long long pos, int sushi_num) {
  long long clock = sushi[sushi_num].pos - pos;
  long long unclock = pos + C - sushi[sushi_num].pos;
  if (clock < unclock) {
    return clock;
  } else {
    return unclock;
  }
}
int main(void) {
  cin >> N >> C;
  long long m1, m2;
  for (int i = 0; i < N; i++) {
    scanf("%lld%lld", &m1, &m2);
    sushi[i].pos = m1;
    sushi[i].cal = m2;
  }
  long long maxcal_clock = 0;
  long long cumcal_clock[100000] = {};
  long long answer = 0;
  cumcal_clock[0] = sushi[0].cal - sushi[0].pos;
  for (int i = 1; i < N; i++) {
    cumcal_clock[i] =
        cumcal_clock[i - 1] + sushi[i].cal - (sushi[i].pos - sushi[i - 1].pos);
    if (cumcal_clock[i] > answer) {
      answer = cumcal_clock[i];
    }
  }
  long long cumcal_u_counter[100000] = {};
  cumcal_u_counter[N - 1] = sushi[N - 1].cal - (C - sushi[N - 1].pos);
  for (int i = N - 2; i >= 0; i--) {
    cumcal_u_counter[i] = cumcal_u_counter[i + 1] + sushi[i].cal -
                          (sushi[i + 1].pos - sushi[i].pos);
    if (cumcal_u_counter[i] > answer) {
      answer = cumcal_u_counter[i];
    }
  }
  long long tempanswer = 0;
  for (int i = 0; i < N; i++) {
    for (int j = N - 1; j > i; j--) {
      tempanswer = cumcal_clock[i] + cumcal_u_counter[j] - sushi[i].pos;
      if (tempanswer > answer) {
        answer = tempanswer;
      }
    }
  }
  for (int i = N - 1; i >= 0; i--) {
    for (int j = 0; j < i; j++) {
      tempanswer = cumcal_clock[j] + cumcal_u_counter[i] - (C - sushi[i].pos);
      if (tempanswer > answer) {
        answer = tempanswer;
      }
    }
  }
  cout << answer << endl;
}
