#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
const long double eps = 1e-8;
long long read() {
  char ch = getchar();
  long long x = 0;
  int op = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') op = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
  return x * op;
}
void write(long long a) {
  if (a < 0) putchar('-'), a = -a;
  if (a >= 10) write(a / 10);
  putchar(a % 10 + '0');
}
long long ksm(long long x, long long p) {
  long long ret = 1;
  for (; p; p >>= 1, x = x * x)
    if (p & 1) ret = ret * x;
  return ret;
}
int n;
long long m, l[500005], r[500005], ls[500005], rs[500005], ans;
struct node {
  long long x, val;
} a[500005];
int main() {
  n = read(), m = read();
  for (int i = (1); i <= (n); i++) {
    a[i].x = read(), a[i].val = read();
    a[i + n] = a[i];
  }
  long long now = 0;
  for (int i = (n); i >= (1); i--) {
    now += a[i].val;
    l[i] = now - 2ll * (m - a[i].x);
    ls[i] = now - (m - a[i].x);
  }
  now = 0;
  for (int i = (n + 1); i <= (2 * n); i++) {
    now += a[i].val;
    r[i] = now - 2ll * a[i].x;
    rs[i] = now - a[i].x;
  }
  rs[n] = 0;
  for (int i = (n + 1); i <= (2 * n); i++) rs[i] = max(rs[i - 1], rs[i]);
  ls[n + 1] = 0;
  for (int i = (n); i >= (1); i--) ls[i] = max(ls[i + 1], ls[i]);
  ans = 0;
  for (int i = (1); i <= (n + 1); i++)
    ans = max(ans, l[i] + rs[n - (n - i + 1) + n]);
  for (int i = (n + 1); i <= (2 * n); i++) ans = max(ans, r[i] + ls[i - n + 1]);
  cout << ans << endl;
  return 0;
}
