#include <bits/stdc++.h>
long long int temp[100000];
void MergeSort(long long int x[], long long int left, long long int right) {
  long long int mid, i, j, k;
  if (left >= right) return;
  mid = (left + right) / 2;
  MergeSort(x, left, mid);
  MergeSort(x, mid + 1, right);
  for (i = left; i <= mid; i++) temp[i] = x[i];
  for (i = mid + 1, j = right; i <= right; i++, j--) temp[i] = x[j];
  i = left;
  j = right;
  for (k = left; k <= right; k++)
    if (temp[i] <= temp[j])
      x[k] = temp[i++];
    else
      x[k] = temp[j--];
}
int main(void) {
  int N, front, end;
  long long int C, x[100003], v[100003], tmp1 = 0, tmp2 = 0, cal = 0, max = 0,
                                         tmp = 0;
  scanf("%d %lld", &N, &C);
  for (int i = 1; i <= N; i++) {
    scanf("%lld %lld", &x[i], &v[i]);
  }
  x[0] = 0, x[N + 1] = C;
  front = 0, end = N + 1;
  while (end - front != 1) {
    tmp1 = cal + v[front + 1] - (x[front + 1] + (C - x[end]));
    if (x[front + 1] <= (C - x[end])) {
      tmp1 -= x[front + 1];
    } else {
      tmp1 -= (C - x[end]);
    }
    tmp2 = cal + v[end - 1] - (x[front] + (C - x[end - 1]));
    if (x[front] >= (C - x[end - 1])) {
      tmp2 -= (C - x[end - 1]);
    } else {
      tmp2 -= x[front];
    }
    if (tmp1 >= tmp2) {
      cal = tmp1;
      front++;
    } else {
      cal = tmp2;
      end--;
    }
    if (cal > max) {
      max = cal;
    }
    cal += (x[front] + (C - x[end]));
    if (x[front] >= (C - x[end])) {
      cal += (C - x[end]);
    } else {
      cal += x[front];
    }
  }
  tmp = 0;
  for (int i = 1; i <= N; i++) {
    tmp += v[i];
    cal = tmp - x[i];
    if (cal > max) {
      max = cal;
    }
  }
  tmp = 0;
  for (int i = N; i >= 0; i--) {
    tmp += v[i];
    cal = tmp - (C - x[i]);
    if (cal > max) {
      max = cal;
    }
  }
  printf("%lld\n", max);
  return 0;
}
