#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long int N, C;
  long int maxr = -1, maxl = -1, maxl1[N + 1], maxr1[N + 1];
  cin >> N >> C;
  long int x[N + 2], v[N], sumr[N + 1], suml[N + 1];
  x[0] = 0;
  x[N + 1] = C;
  for (int i = 0; i < N; i++) {
    cin >> x[i + 1] >> v[i];
  }
  sumr[0] = 0;
  for (int i = 1; i <= N; i++) {
    sumr[i] = sumr[i - 1] + v[i - 1];
  }
  suml[0] = 0;
  for (int i = 1; i <= N; i++) {
    suml[i] = suml[i - 1] + v[N - i];
  }
  maxl1[0] = 0;
  for (int J = 1; J <= N; J++) {
    long int maxl0 = suml[J] - C + x[N + 1 - J];
    maxl1[J] = max(maxl1[J - 1], maxl0);
  }
  for (int I = 0; I <= N; I++) {
    long int res = sumr[I] + suml[0];
    res -= x[I];
    if (maxr < res) maxr = res;
    res = sumr[I] - x[I] * 2;
    res += maxl1[N - I];
    if (maxr < res) maxr = res;
  }
  maxr1[0] = 0;
  for (int I = 1; I <= N; I++) {
    long int maxr0 = sumr[I] - x[I];
    maxr1[I] = max(maxr1[I - 1], maxr0);
  }
  for (int J = 0; J <= N; J++) {
    long int res = sumr[J] + suml[0];
    res -= C - x[N + 1 - J];
    if (maxl < res) maxl = res;
    res = suml[J] - 2 * C + 2 * x[N + 1 - J];
    res += maxr1[N - J];
    if (maxl < res) maxl = res;
  }
  cout << max(maxr, maxl) << endl;
}
