#include <bits/stdc++.h>
long long mymax(long long x, long long y) { return x > y ? x : y; }
int mymin(int x, int y) { return x < y ? x : y; }
int myabs(int x) { return x > 0 ? x : -x; }
const int MAXN = 110000;
struct Nod {
  long long w, c;
  Nod() { w = c = 0; }
} p[MAXN * 2];
struct Nod2 {
  long long c;
  int p;
} p2[MAXN * 2];
Nod2 q[3][MAXN * 2];
int tou[3], wei[3];
int n;
long long c;
void add(int x, int c, int k) {
  Nod2 now;
  now.c = c;
  now.p = x;
  while (tou[k] <= wei[k] and q[k][wei[k]].c <= now.c) wei[k]--;
  q[k][++wei[k]] = now;
}
long long ans = 0;
int main() {
  scanf("%d%lld", &n, &c);
  for (int i = n; i >= 1; i--) {
    scanf("%lld%lld", &p[i].c, &p[i].w);
    p[i].w += p[i + 1].w;
    ans = mymax(ans, p[i].w - p[i].c);
  }
  for (int i = n + 1; i <= 2 * n; i++) {
    p[i].w = p[1].w - p[i - n + 1].w;
    p[i].c = c - p[i - n].c;
    ans = mymax(ans, p[i].w - p[i].c);
  }
  tou[1] = 1;
  wei[1] = 1;
  q[1][1].c = p[2].w - p[2].c * 2;
  q[1][1].p = 2;
  for (int i = 3; i <= n; i++) add(i, p[i].w - 2 * p[i].c, 1);
  tou[2] = 1;
  wei[2] = 1;
  q[2][1].c = p[n + 1].w - p[n + 1].c * 2;
  ans = mymax(ans, q[1][tou[1]].c + q[2][tou[2]].c);
  for (int i = n + 2; i <= 2 * n - 1; i++) {
    while (q[1][tou[1]].p <= i - n) tou[1]++;
    add(i, p[i].w - 2 * p[i].c, 2);
    ans = mymax(ans, q[1][tou[1]].c + q[2][tou[2]].c);
  }
  printf("%lld\n", ans);
}
