#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];
int dfs(long long int u, long long int v, long long int k) {
  ans = max(ans, v - k);
  if (visited[u] == 3) return 0;
  visited[u] += 1;
  for (int i = 0; i < g[u].size(); ++i) {
    if (visited[g[u][i].first] == 0)
      dfs(g[u][i].first, v + g[u][i].second.second, k + g[u][i].second.first);
    else
      dfs(g[u][i].first, v, k + g[u][i].second.first);
  }
  return 0;
}
int main() {
  cin >> n >> c;
  std::vector<pair<long long int, long long int> > a;
  for (int i = 0; i < n; ++i) {
    long long r, c;
    cin >> r >> c;
    a.push_back({r, c});
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n; ++i) {
    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) {
    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}});
  }
  dfs(0, 0, 0);
  cout << ans << endl;
}
