#include <bits/stdc++.h>
using namespace std;
const int N = 100050;
int gi() {
  char ch = getchar();
  int x = 0, q = 0;
  while (ch < '0' || ch > '9') q = ch == '-' ? 1 : q, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return q ? -x : x;
}
int n, v[N];
long long s[N], x[N], C, ans;
int main() {
  int n = gi();
  cin >> C;
  for (int i = 1; i <= n; ++i)
    scanf("%lld", &x[i]), x[i + n] = x[i], v[i] = v[i + n] = gi();
  for (int i = n + 1; i <= 2 * n; ++i) s[i] = s[i - 1] + v[i];
  for (int i = n + 1; i <= 2 * n; ++i) s[i] -= x[i];
  for (int i = n + 1; i <= 2 * n; ++i)
    s[i] = (s[i] > s[i - 1] ? s[i] : s[i - 1]);
  long long sum = 0;
  for (int i = n; i >= 1; --i) {
    sum += v[i];
    ans = (ans > sum - C + x[i] ? ans : sum - C + x[i]);
    ans = (ans > sum - 2 * (C - x[i]) + s[i + n - 1]
               ? ans
               : sum - 2 * (C - x[i]) + s[i + n - 1]);
  }
  memset(s, 0, sizeof(s));
  reverse(x + 1, x + 2 * n + 1), reverse(v + 1, v + 2 * n + 1);
  for (int i = n + 1; i <= 2 * n; ++i) s[i] = s[i - 1] + v[i];
  for (int i = n + 1; i <= 2 * n; ++i) s[i] -= C - x[i];
  for (int i = n + 1; i <= 2 * n; ++i)
    s[i] = (s[i] > s[i - 1] ? s[i] : s[i - 1]);
  sum = 0;
  for (int i = n; i >= 1; --i) {
    sum += v[i];
    ans = (ans > sum - x[i] ? ans : sum - x[i]);
    ans = (ans > sum - 2 * x[i] + s[i + n - 1] ? ans
                                               : sum - 2 * x[i] + s[i + n - 1]);
  }
  cout << ans;
  return 0;
}
