#include <bits/stdc++.h>
using namespace std;
long long n, c, x[100001], v[100001], ni[100001], cur;
long long res = 0, ji, nv[100001], book, ans, qian[100001], hou[100001];
int main() {
  scanf("%lld%lld", &n, &c);
  for (int i = 1; i <= n; i++) scanf("%lld%lld", &x[i], &v[i]);
  for (int i = 1; i <= n; i++) {
    ni[i] = c - x[n - i + 1];
    nv[i] = v[n - i + 1];
    qian[i] = qian[i - 1] + v[i];
    hou[i] = hou[i - 1] + nv[i];
  }
  for (int i = 1; i <= n; i++) {
    qian[i] -= x[i];
    hou[i] -= ni[i];
  }
  for (int i = 1; i <= n; i++) {
    res = max(res, qian[i]);
    cur = qian[i];
    book = 0;
    ji = 0;
    for (int j = 1; j <= n - i; j++) {
      if (hou[j] > ji) {
        ji = hou[j];
        book = j;
      }
    }
    res = max(res, cur + ji - x[i]);
  }
  for (int i = 1; i <= n; i++) {
    ans = max(ans, hou[i]);
    cur = hou[i];
    book = 0;
    ji = 0;
    for (int j = 1; j <= n - i; j++) {
      if (qian[j] > ji) {
        ji = qian[j];
        book = j;
      }
    }
    ans = max(ans, cur + ji - ni[i]);
  }
  res = max(res, ans);
  printf("%lld\n", res);
  return 0;
}
