#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f, mo = 1e9 + 7;
template <typename A, typename B>
inline bool upmx(A &first, const B &second) {
  return first < second ? first = second, 1 : 0;
}
template <typename A, typename B>
inline bool upmn(A &first, const B &second) {
  return first > second ? first = second, 1 : 0;
}
template <typename T>
inline T gcd(T first, T second) {
  for (; second; swap(first, second)) first %= second;
  return first;
}
inline int Pow(int a, int b, int p = mo) {
  int r = 1;
  for (; b; b >>= 1, a = 1ll * a * a % p)
    if (b & 1) r = 1ll * r * a % p;
  return r;
}
const int N = 1e5 + 11;
int n;
long long a[N];
int b[N];
long long f[N], g[N], ff[N], gg[N];
long long C;
int read() {
  char ch = getchar();
  int f = 0, first = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') first = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    f = (f << 1) + (f << 3) + ch - '0';
    ch = getchar();
  }
  return f * first;
}
int main() {
  n = read(), C = read();
  for (int i = 1; i <= n; i++) a[i] = read(), b[i] = read();
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    f[i] = f[i - 1] + b[i];
  }
  for (int i = 1; i <= n; i++) f[i] -= a[i];
  for (int i = 1; i <= n; i++) {
    ff[i] = max(f[i], ff[i - 1]);
  }
  ans = ff[n];
  for (int i = n; i; i--) {
    g[i] = g[i + 1] + b[i];
  }
  for (int i = n; i; i--) {
    g[i] -= (C - a[i]);
    upmx(ans, g[i]);
    upmx(ans, g[i] - (C - a[i]) + ff[i - 1]);
  }
  for (int i = n; i; i--) gg[i] = max(gg[i + 1], g[i]);
  for (int i = 1; i <= n; i++) {
    upmx(ans, f[i] - a[i] + gg[i + 1]);
  }
  cout << ans;
}
