#include <bits/stdc++.h>
inline int scan() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void Out(int a) {
  if (a < 0) {
    putchar('-');
    a = -a;
  }
  if (a >= 10) Out(a / 10);
  putchar(a % 10 + '0');
}
using namespace std;
struct A {
  int x;
  long long v;
};
int cmp(A a, A b) { return a.x < b.x; }
A a[100005];
long long sum[100005];
long long hou[100005];
long long maxs[100005];
long long maxs1[100005];
int main() {
  ios::sync_with_stdio(false);
  long long n, c;
  cin >> n >> c;
  for (int i = 1; i <= n; i++) cin >> a[i].x >> a[i].v;
  sort(a + 1, a + 1 + n, cmp);
  long long ans = 0;
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i].v;
  for (int i = n; i >= 1; i--) hou[i] = hou[i + 1] + a[i].v;
  for (int i = n; i >= 1; i--) {
    maxs[i] = max(maxs[i + 1], hou[i] - 2 * (c - a[i].x));
  }
  for (int i = 1; i <= n; i++) {
    maxs1[i] = max(maxs1[i - 1], sum[i] - 2 * a[i].x);
  }
  for (int i = 1; i <= n; i++) {
    ans = max(ans, max(sum[i] - a[i].x + maxs[i + 1], hou[i] - (c - a[i].x)));
    ans = max(ans, max(sum[i] - a[i].x, hou[i] - (c - a[i].x) + maxs1[i - 1]));
  }
  cout << ans << endl;
  return 0;
}
