#include <bits/stdc++.h>
using namespace std;
struct edge {
  int from, to;
  long long cost;
};
vector<pair<long long, long long> > sushi(100010);
vector<pair<long long, long long> > G[100010];
long long N, C;
long long dfs(int i, vector<bool> used, long long ans) {
  used[i] = true;
  if (i == N + 1) return ans;
  long long new_ans = ans;
  bool end = true;
  for (pair<long long, long long> p : G[i]) {
    if (used[p.first]) continue;
    cerr << i << "->" << p.first << ": " << p.second << endl;
    new_ans = max(new_ans, dfs(p.first, used, ans + p.second));
    end = false;
  }
  return new_ans;
}
int main() {
  std::ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> C;
  for (int i = 0; i < N; i++) cin >> sushi[i].first >> sushi[i].second;
  for (int i = 0; i < N; i++) {
    G[0].push_back(make_pair(
        i + 1, sushi[i].second - min(sushi[i].first, C - sushi[i].first)));
    long long j = (i == 0 ? N - 1 : i - 1);
    long long dist = abs(sushi[j].first - sushi[i].first);
    G[i + 1].push_back(make_pair(j + 1, sushi[j].second - min(dist, C - dist)));
    G[j + 1].push_back(make_pair(i + 1, sushi[i].second - min(dist, C - dist)));
    G[i + 1].push_back(make_pair(N + 1, 0LL));
  }
  cout << dfs(0, vector<bool>(N + 2, false), 0LL) << endl;
}
