#include <bits/stdc++.h>
using namespace std;
using ll = long long;
class TWO {
 public:
  ll pos;
  ll value;
  TWO(ll pos, ll value) : pos(pos), value(value){};
};
ll get_length(ll C, ll now_position, ll destination_index) {
  return min(abs(now_position - destination_index),
             abs(now_position - (destination_index - C)));
}
int main() {
  ll N, C;
  cin >> N >> C;
  vector<TWO> a;
  a.push_back(TWO(0, 0));
  for (int i = 0; i < N; i++) {
    ll tmp[2];
    cin >> tmp[0] >> tmp[1];
    a.push_back(TWO(tmp[0], tmp[1]));
  }
  sort((a).begin(), (a).end(), [](TWO& a, TWO& b) { return a.pos < b.pos; });
  ll ans = 0;
  ll first_score = 0;
  ll first_position = 0;
  for (int i = 0; i < N + 1; i++) {
    first_score -= get_length(C, first_position, a[i].pos) - a[i].value;
    first_position = a[i].pos;
    ll second_score = first_score;
    ll second_position = first_position;
    ans = max(ans, first_score);
    second_score -= a[i].pos;
    second_position = C;
    for (int j = N; j >= i + 1; j--) {
      second_score += a[j].value - (second_position - a[j].pos);
      second_position = a[j].pos;
      ans = max(ans, second_score);
    }
  }
  first_score = 0;
  first_position = 0;
  for (int i = N; i >= 0; i--) {
    first_score -= get_length(C, first_position, a[i].pos) - a[i].value;
    first_position = a[i].pos;
    ll second_score = first_score;
    ll second_position = first_position;
    ans = max(ans, first_score);
    second_score -= C - first_position;
    second_position = 0;
    for (int j = 0; j < i; j++) {
      second_score += a[j].value - (a[j].pos - second_position);
      second_position = a[j].pos;
      ans = max(ans, second_score);
    }
  }
  cout << ans << endl;
}
