#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int maxn = 1e6 + 10;
template <class T>
T mymin(const T a, const T b) {
  return a < b ? a : b;
}
template <class T>
T mymax(const T a, const T b) {
  return a > b ? a : b;
}
long long N, C;
long long dis[maxn], val[maxn], f[maxn], g[maxn], pos[maxn], g1[maxn];
long long sum1[maxn], sum2[maxn];
long long max(long long a, long long b, long long c) {
  return max(a, max(b, c));
}
int main() {
  ios::sync_with_stdio(false);
  cin >> N >> C;
  for (int i = 1; i <= N; i++) cin >> dis[i] >> val[i];
  for (int i = 1; i <= N; i++) {
    sum1[i] = sum1[i - 1] + val[i];
    f[i] = sum1[i] - dis[i];
    if (f[i] > g[i - 1])
      pos[i] = i;
    else
      pos[i] = pos[i - 1];
    g[i] = max(f[i], g[i - 1]);
  }
  for (int i = N; i >= 1; i--) sum2[i] = sum2[i + 1] + val[i];
  for (int i = N; i >= 1; i--)
    sum2[i] -= (C - dis[i]), g1[i] = max(g1[i - 1], sum2[i]);
  long long ans = 0;
  for (int i = N; i >= 1; i--)
    ans = max(ans, g[i - 1] + sum2[i] - min(C - dis[i], dis[pos[i - 1]]));
  cout << max(ans, g[N], g1[1]) << endl;
  return 0;
}
