#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int tx[8] = {-1, 0, 1, -1, 1, -1, 0, 1},
          ty[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int main() {
  ll n, c, x[100010], y[100010], ans = 0, turn = 0, ruir[100010] = {0},
                                 ruil[100010] = {0};
  cin >> n >> c;
  bool fl = true;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> y[i];
  }
  for (int i = 1; i <= n; i++) {
    ruir[i] = ruir[i - 1] + y[i];
  }
  for (int i = n; i >= 0; i--) {
    ruil[i] = ruil[i + 1] + y[i];
  }
  for (int i = 0; i <= n; i++) {
    for (int j = n; j > i; j--) {
      ans = max(ans, ruir[i] + ruil[j] - (min(x[i], c - x[j]) * 2) -
                         max(x[i], c - x[j]));
    }
  }
  ll sum = 0, mm = 0;
  for (int i = 1; i <= n; i++) {
    sum = sum + (y[i] - (x[i] - x[i - 1]));
    mm = max(mm, sum);
  }
  ans = max(ans, mm);
  sum = 0, mm = 0;
  x[n + 1] = c;
  for (int i = n; i >= 1; i--) {
    sum = sum + (y[i] - (x[i + 1] - x[i]));
    mm = max(mm, sum);
  }
  ans = max(mm, ans);
  cout << ans << endl;
}
