#include <bits/stdc++.h>
long long x[100000 + 100];
long long v[100000 + 100];
long long my_max(long long a, long long b) { return a > b ? a : b; }
long long my_min(long long a, long long b) { return a < b ? a : b; }
int main() {
  int N;
  long long C;
  scanf("%d %lld", &N, &C);
  for (int i = 0; i < N; i++) scanf("%lld %lld", &x[i], &v[i]);
  long long my_maxx = 0;
  for (int i = 0; i < N; i++) {
    long long sum = v[i];
    my_maxx = my_max(my_maxx, sum - my_min(x[i], C - x[i]));
    long long my_maxxx = 0;
    int max_loca = -1;
    int k = (i + 1) % N;
    while (sum > 0 && k != i) {
      int last = (k - 1 + N) % N;
      if (x[last] < x[k])
        sum += (v[k] - (x[k] - x[last]));
      else
        sum += (v[k] - (C - x[last] + x[k]));
      long long dis = my_min(my_min(x[i], C - x[i]), my_min(x[k], C - x[k]));
      my_maxx = my_max(my_maxx, sum - dis);
      k = (k + 1) % N;
    }
  }
  printf("%lld\n", my_maxx);
  return 0;
}
