#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, ruir[100010] = {0},
                                 ruil[100010] = {0}, sumr[100010] = {0},
                                 suml[100010] = {0};
  pair<ll, ll> mr[100010], ml[100010];
  cin >> n >> c;
  x[n + 1] = c;
  mr[0].first = 0, mr[0].second = 0, ml[n + 1].first = 0, ml[n + 1].second = c;
  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];
    sumr[i] = ruir[i - 1] + y[i] - x[i];
    if (mr[i - 1].first < sumr[i]) {
      mr[i].first = ruir[i];
      mr[i].second = x[i];
    } else {
      mr[i].first = mr[i - 1].first;
      mr[i].second = mr[i - 1].second;
    }
  }
  for (int i = n; i > 0; i--) {
    ruil[i] = ruil[i + 1] + y[i];
    suml[i] = ruil[i + 1] + y[i] - (c - x[i]);
    if (ml[i + 1].first < suml[i]) {
      ml[i].first = ruil[i];
      ml[i].second = c - x[i];
    } else {
      ml[i].first = ml[i + 1].first;
      ml[i].second = ml[i + 1].second;
    }
  }
  for (int i = 1; i <= n; i++) {
    ans = max(ans, ruir[i] + ml[i + 1].first -
                       (min(x[i], ml[i + 1].second) * 2 +
                        max(x[i], ml[i + 1].second)));
  }
  for (int i = n; i >= 0; i--) {
    ans = max(ans, ruil[i] + mr[i - 1].first -
                       (min(c - x[i], mr[i - 1].second) * 2 +
                        max(c - x[i], mr[i - 1].second)));
  }
  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;
  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;
}
