#include <bits/stdc++.h>
using namespace std;
const int tam = 100002;
long long n, C;
long long dis[tam];
long long nut[tam];
long long suf[tam];
long long pre[tam];
struct RMQ {
  pair<long long, int> vec[17][1 << (17 + 1)];
  pair<long long, int> &operator[](int p) { return vec[0][p]; }
  pair<long long, int> get(int i, int j) {
    int p = 31 - __builtin_clz(j - i);
    if (vec[p][i].first > vec[p][j - (1 << p)].first) {
      return vec[p][i];
    } else
      return vec[p][j - (1 << p)];
  }
  void build(int n) {
    int mp = 31 - __builtin_clz(n);
    for (int p = 0; p < mp; ++p)
      for (int x = 0; x < n - (1 << p); ++x) {
        vec[p + 1][x] = max(vec[p][x], vec[p][x + (1 << p)]);
        if (vec[p][x].first > vec[p][x + (1 << p)].first) {
          vec[p + 1][x] = vec[p][x];
        } else
          vec[p + 1][x] = vec[p][x + (1 << p)];
      }
  }
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> C;
  long long ans = 0;
  RMQ rmq;
  for (int i = 0; i < n; ++i) {
    cin >> dis[i + 1] >> nut[i + 1];
    pre[i + 1] = pre[i] + nut[i + 1] + dis[i] - dis[i + 1];
    ans = max(ans, pre[i + 1]);
    rmq[i + 1] = pair<long long, int>(pre[i + 1], i + 1);
  }
  rmq.build(n + 1);
  dis[n + 1] = C;
  int i;
  for (i = n; i >= 1; --i) {
    suf[i] = suf[i + 1] + nut[i] + (C - dis[i + 1]) - (C - dis[i]);
    ans = max(ans, suf[i]);
  }
  for (i = n; i >= 1; --i) {
    pair<long long, int> res = rmq.get(0, i);
    long long cost = res.first + suf[i] - min(dis[res.second], C - dis[i]);
    ans = max(ans, cost);
  }
  cout << ans << '\n';
  return 0;
}
