#include <bits/stdc++.h>
using namespace std;
const long long Maxn = 100010;
long long a[Maxn], val[Maxn], sum1[Maxn], sum2[Maxn];
long long n, C;
long long seg1[Maxn << 2], seg2[Maxn];
long long _max(long long x, long long y) { return x > y ? x : y; }
void build_tree(long long now, long long L, long long R) {
  if (L < R) {
    long long mid = L + R >> 1, lc = now << 1, rc = now << 1 | 1;
    build_tree(lc, L, mid);
    build_tree(rc, mid + 1, R);
    seg1[now] = _max(seg1[lc], seg1[rc]);
    seg2[now] = _max(seg2[lc], seg2[rc]);
  } else {
    seg1[now] = sum1[L], seg2[now] = sum2[L];
  }
}
long long qry1(long long now, long long L, long long R, long long l,
               long long r) {
  if (l > r) return 0;
  if (L == l && R == r) return seg1[now];
  long long mid = L + R >> 1, lc = now << 1, rc = now << 1 | 1;
  if (r <= mid)
    return qry1(lc, L, mid, l, r);
  else if (l > mid)
    return qry1(rc, mid + 1, R, l, r);
  else
    return _max(qry1(lc, L, mid, l, mid), qry1(rc, mid + 1, R, mid + 1, r));
}
long long qry2(long long now, long long L, long long R, long long l,
               long long r) {
  if (l > r) return 0;
  if (L == l && R == r) return seg2[now];
  long long mid = L + R >> 1, lc = now << 1, rc = now << 1 | 1;
  if (r <= mid)
    return qry2(lc, L, mid, l, r);
  else if (l > mid)
    return qry2(rc, mid + 1, R, l, r);
  else
    return _max(qry2(lc, L, mid, l, mid), qry2(rc, mid + 1, R, mid + 1, r));
}
int main() {
  long long i, j, k;
  scanf("%lld%lld", &n, &C);
  for (i = 1; i <= n; i++) scanf("%lld%lld", &a[i], &val[i]);
  a[n + 1] = C;
  for (i = n; i >= 1; i--)
    sum1[i] = sum1[i + 1] + val[i] - (a[i + 1] - a[i]),
    sum2[i] = sum2[i + 1] + val[i] - 2 * (a[i + 1] - a[i]);
  build_tree(1, 1, n);
  long long ans = _max(qry1(1, 1, n, 1, n), 0), sv = 0;
  for (i = 1; i <= n; i++) {
    long long x = lower_bound(a + 1, a + n + 1, C - a[i]) - a;
    x = _max(x, i + 1);
    sv += val[i];
    ans = _max(ans, _max(sv - 2 * a[i] + qry1(1, 1, n, i + 1, x - 1),
                         sv - a[i] + _max(qry2(1, 1, n, x, n), 0)));
  }
  printf("%lld\n", ans);
  return 0;
}
