#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, c;
  cin >> n >> c;
  vector<pair<long long, long long> > vec(2 * n);
  for (int i = 0; i < n; i++) {
    cin >> vec[i].first >> vec[i].second;
    vec[i + n].first = vec[i].first;
    vec[i + n].second = vec[i].second;
    vec[i].first = c - vec[i].first;
  }
  long long ans = 0;
  long long standing_point = n;
  for (long long turning_point = standing_point; turning_point < 2 * n;
       turning_point++) {
    vector<long long> value(n * 2, 0);
    long long distance;
    long long last_pos = 0;
    long long i;
    long long counter = 0;
    for (i = standing_point; i <= turning_point; i++) {
      distance = vec[i].first - last_pos;
      last_pos = vec[i].first;
      value[counter] = vec[i].second - distance;
      if (counter > 0) {
        value[counter] += value[counter - 1];
      }
      counter++;
    }
    if (counter == n) {
      ;
    } else {
      i = n - 1;
      distance = vec[i].first + last_pos;
      last_pos = vec[i].first;
      value[counter] = vec[i].second - distance;
      if (counter > 0) {
        value[counter] += value[counter - 1];
      }
      counter++;
      i--;
      for (; counter < n; counter++, i--) {
        distance = vec[i].first - last_pos;
        last_pos = vec[i].first;
        value[counter] = vec[i].second - distance;
        if (counter > 0) {
          value[counter] += value[counter - 1];
        }
      }
    }
    for (int i = 0; i < n; i++) {
      ans = max(ans, value[i]);
    }
  }
  reverse(vec.begin(), vec.end());
  for (long long turning_point = standing_point; turning_point < 2 * n;
       turning_point++) {
    vector<long long> value(n * 2, 0);
    long long distance;
    long long last_pos = 0;
    long long i;
    long long counter = 0;
    for (i = standing_point; i <= turning_point; i++) {
      distance = vec[i].first - last_pos;
      last_pos = vec[i].first;
      value[counter] = vec[i].second - distance;
      if (counter > 0) {
        value[counter] += value[counter - 1];
      }
      counter++;
    }
    if (counter == n) {
      ;
    } else {
      i = n - 1;
      distance = vec[i].first + last_pos;
      last_pos = vec[i].first;
      value[counter] = vec[i].second - distance;
      if (counter > 0) {
        value[counter] += value[counter - 1];
      }
      counter++;
      i--;
      for (; counter < n; counter++, i--) {
        distance = vec[i].first - last_pos;
        last_pos = vec[i].first;
        value[counter] = vec[i].second - distance;
        if (counter > 0) {
          value[counter] += value[counter - 1];
        }
      }
    }
    for (int i = 0; i < n; i++) {
      ans = max(ans, value[i]);
    }
  }
  cout << ans << endl;
}
