#include <bits/stdc++.h>
using namespace std;
const int N = 200000;
int n;
long long c, ans = 0;
long long f[N][2], g[N][2];
inline void ck_max(long long &a, long long b) {
  if (a < b) a = b;
}
struct tSushi {
  long long x;
  int v;
} s[N];
struct deleteable_heap {
  priority_queue<long long> q1, q2;
  inline void push(long long val) { q1.push(val); }
  inline void check() {
    while (q1.top() == q2.top()) q1.pop(), q2.pop();
  }
  inline void erase(long long val) { q2.push(val); }
  inline long long top() {
    check();
    return q1.top();
  }
} heap_1, heap_2;
int main() {
  memset(f, 0, sizeof(f));
  memset(g, 0, sizeof(g));
  scanf("%d%lld", &n, &c);
  for (int i = 1; i <= n; i++) scanf("%lld%d", &s[i].x, &s[i].v);
  for (int i = 1; i <= n; i++) f[i][0] = f[i - 1][0] + s[i].v, f[i][1] = s[i].x;
  for (int i = n; i >= 1; i--)
    g[i][0] = g[i + 1][0] + s[i].v, g[i][1] = c - s[i].x;
  for (int i = 1; i <= n; i++)
    ck_max(ans, f[i][0] - f[i][1]), ck_max(ans, g[i][0] - g[i][1]);
  for (int i = 1; i <= n; i++)
    heap_1.push(g[i][0] - g[i][1]), heap_2.push(g[i][0] - 2 * g[i][1]);
  for (int i = 1; i < n; i++) {
    heap_1.erase(g[i][0] - g[i][1]);
    heap_2.erase(g[i][0] - 2 * g[i][1]);
    long long tmp_1 = heap_1.top() + f[i][0] - 2 * f[i][1];
    long long tmp_2 = heap_2.top() + f[i][0] - f[i][1];
    ck_max(ans, tmp_1);
    ck_max(ans, tmp_2);
  }
  printf("%lld\n", ans);
  return 0;
}
