#include <bits/stdc++.h>
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6;
const long long LINF = 1e18;
using namespace std;
long long n, cnt = 0, ans = 0, a, b, d, cmp, cmpp, m, h, w, x[ohara], v[ohara],
             y, sum = 0, pos, c;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
bool fl;
struct edge {
  int to, cost;
};
long long ans1 = 0, ans2 = 0, ans3 = 0, ans4 = 0;
long long access3[ohara];
long long access4[ohara];
long long cou3 = 0, cou4 = 0;
long long tmp3, tmp4;
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> c;
  for (long long(i) = 0; (i) < (int)(n); (i)++) cin >> x[i] >> v[i];
  for (long long(i) = 0; (i) < (int)(n); (i)++) {
    cnt += v[i];
    if (i != n - 1) {
      access4[cou4++] = cnt - x[i];
    }
    ans1 = max(ans1, cnt - x[i]);
  }
  cnt = 0;
  for (long long i = (n - 1); i >= (0); i--) {
    cnt += v[i];
    if (i != 0) {
      access3[cou3++] = cnt - c + x[i];
    }
    ans2 = max(ans2, cnt - c + x[i]);
  }
  for (long long i = (1); i < (cou3); i++) {
    access3[i] = max(access3[i], access3[i - 1]);
  }
  for (long long i = (1); i < (cou4); i++) {
    access4[i] = max(access4[i], access4[i - 1]);
  }
  reverse(access3, access3 + cou3);
  cnt = 0;
  for (long long(i) = 0; (i) < (int)(n - 1); (i)++) {
    cnt += v[i];
    tmp3 = cnt - x[i];
    tmp3 += access3[i];
    tmp3 -= x[i];
    ans3 = max(ans3, tmp3);
  }
  cnt = 0;
  for (long long i = (n - 1); i >= (1); i--) {
    cnt += v[i];
    tmp4 = cnt - c + x[i];
    tmp4 -= c - x[i];
    tmp4 += access4[i];
    ans4 = max(ans4, tmp4);
  }
  cout << (max({ans1, ans2, ans3, ans4})) << endl;
  return 0;
}
