#include <bits/stdc++.h>
using namespace std;
int N;
long C;
long energy(long a, long b) {
  long ab = a + b;
  return (a < b) ? ab + a : ab + b;
}
int main() {
  scanf("%d %ld", &N, &C);
  long x[N];
  long v[N];
  for (int i = 0; i < N; ++i) {
    scanf("%ld %ld", &x[i], &v[i]);
  }
  long vs1[N];
  for (int i = 0; i < N; ++i) {
    vs1[i] = (i == 0) ? v[0] : vs1[i - 1] + v[i];
  }
  long vsN[N];
  for (int i = N - 1; i > -1; --i) {
    vsN[i] = (i == N - 1) ? v[N - 1] : vsN[i + 1] + v[i];
  }
  long ans = 0;
  for (int i = 0; i < N; ++i) {
    long e = energy(x[i], 0);
    ans = max(vs1[i] - e, ans);
  }
  for (int i = N - 1; i > -1; --i) {
    long e = energy(0, C - x[i]);
    ans = max(vsN[i] - e, ans);
  }
  for (int a = 0; a < N; ++a) {
    for (int b = N - 1; b > 0; --b) {
      if (a >= b) break;
      long e = energy(x[a], C - x[b]);
      ans = max(vs1[a] + vsN[b] - e, ans);
    }
  }
  printf("%ld\n", ans);
  return 0;
}
