#include <bits/stdc++.h>
const int MAX_N = 1 << 17;
long long x[MAX_N];
long long v[MAX_N];
int rmq_n;
long long rmq[4][2 * MAX_N - 1];
void init(int n) {
  rmq_n = 1;
  while (rmq_n < n) rmq_n *= 2;
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < 2 * rmq_n; j++) {
      rmq[i][j] = 0;
    }
}
long long max(long long a, long long b) { return a > b ? a : b; }
long long query_sub(long long p[], int a, int b, int k, int l, int r) {
  if (r <= a || b <= l) return 0;
  if (a <= l && r <= b)
    return p[k];
  else {
    long long vl = query_sub(p, a, b, k * 2 + 1, l, (l + r) / 2);
    long long vr = query_sub(p, a, b, k * 2 + 2, (l + r) / 2, r);
    return max(vl, vr);
  }
}
long long query(long long p[], int a, int b) {
  return query_sub(p, a, b, 0, 0, rmq_n);
}
int main() {
  int n;
  long long c;
  scanf("%d %lld", &n, &c);
  init(n);
  for (int i = 0; i < n; i++) {
    scanf("%lld %lld", &x[i], &v[i]);
  }
  long long kcal = 0;
  for (int i = 0; i < n; i++) {
    kcal += v[i];
    rmq[0][i + rmq_n - 1] = kcal - x[i];
    rmq[1][i + rmq_n - 1] = kcal - 2 * x[i];
  }
  kcal = 0;
  for (int i = n - 1; i >= 0; i--) {
    kcal += v[i];
    rmq[2][i + rmq_n - 1] = kcal - (c - x[i]);
    rmq[3][i + rmq_n - 1] = kcal - 2 * (c - x[i]);
  }
  for (int i = rmq_n - 2; i >= 0; i--) {
    for (int j = 0; j < 4; j++)
      rmq[j][i] = max(rmq[j][i * 2 + 1], rmq[j][i * 2 + 2]);
  }
  long long m = 0;
  for (int i = 0; i <= n; i++) {
    long long v0 = query(rmq[0], 0, i);
    long long v1 = query(rmq[1], 0, i);
    long long v2 = query(rmq[2], i, n);
    long long v3 = query(rmq[3], i, n);
    long long v = max(max(max(v0, v2), v0 + v3), v1 + v2);
    if (m < v) m = v;
  }
  printf("%lld\n", m);
  return 0;
}
