#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
long long mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
long long llmax = 9223372036854775807;
long long llmin = -9223372036854775807;
long long inf = llmax / 2;
long long rgt[200000];
long long lft[200000];
long long rgtend[200000];
long long rgtback[200000];
long long lftend[200000];
long long lftback[200000];
int main() {
  long long N, C;
  cin >> N >> C;
  long long x[N], v[N];
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> v[i];
  }
  rgt[0] = 0;
  lft[0] = 0;
  for (int i = 0; i < N; i++) {
    rgt[i + 1] = rgt[i] + v[i];
    lft[i + 1] = lft[i] + v[N - 1 - i];
  }
  rgtend[0] = 0;
  rgtback[0] = 0;
  lftend[0] = 0;
  lftback[0] = 0;
  for (int i = 0; i < N; i++) {
    rgtend[i + 1] = max(rgtend[i], rgt[i + 1] - x[i]);
    rgtback[i + 1] = max(rgtback[i], rgt[i + 1] - x[i] * 2);
    lftend[i + 1] = max(lftend[i], lft[i + 1] - (C - x[N - 1 - i]));
    lftback[i + 1] = max(lftback[i], lft[i + 1] - (C - x[N - 1 - i]) * 2);
  }
  long long rgtmax = 0;
  long long lftmax = 0;
  for (int i = 0; i < N; i++) {
    rgtmax = max(rgtmax, rgtend[i] + lftback[N - i]);
    lftmax = max(lftmax, lftend[i] + rgtback[N - i]);
  }
  cout << max(rgtmax, lftmax) << endl;
}
