#include <bits/stdc++.h>
using namespace std;
int visited[100005] = {0};
long long int ans = 0;
long long int n, c;
std::vector<pair<long long int, pair<long long int, long long int> > >
    g[100005];
void dfs(long long int u, long long int v, long long int k, int b, int d,
         int bf, set<int> s) {
  ans = max(ans, v - k);
  if (g[u][d].first == bf) {
    return;
  }
  s.insert(u);
  if (b) {
    if (s.count(g[u][d].first))
      dfs(g[u][d].first, v, k + g[u][d].second.first, b, d, bf, s);
    else
      dfs(g[u][d].first, v + g[u][d].second.second, k + g[u][d].second.first, b,
          d, bf, s);
  } else {
    dfs(g[u][d].first, v + g[u][d].second.second, k + g[u][d].second.first, b,
        d, bf, s);
    d ^= 1;
    dfs(g[u][d].first, v, k + g[u][d].second.first, b ^ 1, d, u, s);
  }
  return;
}
int main() {
  cin >> n >> c;
  std::vector<pair<long long int, long long int> > a;
  for (int i = 0; i < n; ++i) {
    long long int rr, ff;
    cin >> rr >> ff;
    a.push_back(pair<long long int, long long int>(rr, ff));
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n; ++i) {
    long long int temp = i <= 0 ? 0 : a[i - 1].first;
    g[i].push_back({i + 1, {a[i].first - temp, a[i].second}});
  }
  if (n > 2)
    g[n].push_back({0, {c - a[n - 1].first, 0}}),
        g[0].push_back({n, {c - a[n - 1].first, a[n - 1].second}});
  for (int i = 1; i <= n; ++i) {
    long long int temp = i <= 1 ? 0 : a[i - 2].first;
    g[i].push_back(
        {i - 1, {a[i - 1].first - temp, i > 1 ? a[i - 2].second : 0}});
  }
  set<int> s;
  dfs(0, 0, 0, 0, 0, 0, s);
  dfs(0, 0, 0, 0, 1, 0, s);
  cout << ans << endl;
}
