#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5 + 200;
int n, q[MAX_N];
long long prefix[2][MAX_N], C, ans;
int main() {
  scanf("%d%lld", &n, &C);
  for (int i = 1; i <= n; i++) scanf("%lld%lld", &prefix[0][i], &prefix[1][i]);
  for (int i = 1; i <= (n << 1); i++) prefix[1][i] += prefix[1][i - 1];
  int head = 1, tail = 0;
  for (int i = n; i >= 1; i--) {
    while (head <= tail && prefix[1][i] - prefix[0][i] >
                               prefix[1][q[tail]] - prefix[0][q[tail]])
      tail--;
    q[++tail] = i;
    ans = max(ans, prefix[1][i] - prefix[0][i]);
  }
  for (int i = n; i >= 1; i--) {
    while (head <= tail && q[head] >= i) head++;
    ans = max(ans, prefix[1][n] - prefix[1][i - 1] - 2LL * (C - prefix[0][i]) +
                       prefix[1][q[head]] - prefix[0][q[head]]);
    ans = max(ans, prefix[1][n] - prefix[1][i - 1] - (C - prefix[0][i]) +
                       prefix[1][q[head]] - 2LL * prefix[0][q[head]]);
    ans = max(ans, prefix[1][n] - prefix[1][i - 1] - (C - prefix[0][i]));
  }
  printf("%lld\n", ans);
  return 0;
}
