#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;
class SegmentTree {
 private:
  long long n;
  long long s;
  vector<long long> data;

 public:
  SegmentTree(long long m, long long t);
  long long operation(long long t1, long long t2);
  void update(long long k, long long a);
  long long query(long long a, long long b);
  long long ans(long long a, long long b, long long k, long long l,
                long long r);
};
SegmentTree::SegmentTree(long long m, long long t) {
  n = 1;
  while (n < m) n *= 2;
  for (long long i = 0; i < 2 * n - 1; i++) {
    data.push_back(t);
  }
  s = t;
}
long long SegmentTree::operation(long long t1, long long t2) {
  return max(t1, t2);
}
void SegmentTree::update(long long k, long long a) {
  k += n - 1;
  data[k] = a;
  while (k > 0) {
    k = (k - 1) / 2;
    data[k] = operation(data[k * 2 + 1], data[k * 2 + 2]);
  }
}
long long SegmentTree::query(long long a, long long b) {
  return ans(a, b, 0, 0, n);
}
long long SegmentTree::ans(long long a, long long b, long long k, long long l,
                           long long r) {
  if (r <= a || b <= l) return s;
  if (a <= l && r <= b) {
    return data[k];
  } else {
    long long vl = ans(a, b, k * 2 + 1, l, (l + r) / 2);
    long long vr = ans(a, b, k * 2 + 2, (l + r) / 2, r);
    return operation(vl, vr);
  }
}
int main() {
  ll n, c, x[100000], v[100000];
  scanf("%lld %lld", &n, &c);
  for (int i = 0; i < n; i++) {
    scanf("%lld %lld", &x[i], &v[i]);
  }
  ll sum1 = 0, sum2 = 0, mx1 = 0, mx2 = 0;
  SegmentTree s1(n, -INF), s2(n, -INF);
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      sum1 += v[i] - x[i];
      sum2 += v[n - i - 1] - (c - x[n - i - 1]);
    } else {
      sum1 += v[i] - x[i] + x[i - 1];
      sum2 += v[n - i - 1] - (c - x[n - i - 1]) + (c - x[n - i]);
    }
    mx1 = max(mx1, sum1);
    s1.update(i, mx1);
    mx2 = max(mx2, sum2);
    s2.update(i, mx2);
  }
  ll mx3 = 0;
  sum1 = 0;
  sum2 = 0;
  for (int i = 0; i < n - 1; i++) {
    if (i == 0) {
      sum1 += v[i] - x[i];
      sum2 += v[n - i - 1] - (c - x[n - i - 1]);
    } else {
      sum1 += v[i] - x[i] + x[i - 1];
      sum2 += v[n - i - 1] - (c - x[n - i - 1]) + (c - x[n - i]);
    }
    mx3 = max(mx3, max(sum1 - x[i] + s2.query(0, n - i - 2),
                       sum2 - (c - x[n - i - 1]) + s1.query(0, n - i - 2)));
  }
  printf("%lld\n", max(max(mx1, mx2), mx3));
}
