#include <bits/stdc++.h>
using namespace std;
long long N, C;
long long x[100005];
int v[100005];
long long sum_A[100005];
long long sum_B[100005];
long long g[100005];
int main() {
  cin >> N >> C;
  x[0] = 0;
  v[0] = 0;
  for (int i = 1; i < N + 1; i++) {
    cin >> x[i] >> v[i];
  }
  sum_A[N] = v[N];
  sum_A[0] = 0;
  for (int i = N - 1; i > 0; i--) {
    sum_A[i] = sum_A[i + 1] + v[i];
  }
  sum_B[0] = 0;
  g[0] = 0;
  long long max = 0;
  for (int i = 1; i < N + 1; i++) {
    sum_B[i] = sum_B[i - 1] + v[i];
    if (sum_B[i] - x[i] > max) {
      g[i] = i;
      max = sum_B[i] - x[i];
    } else {
      g[i] = g[i - 1];
    }
  }
  max = 0;
  for (int i = 0; i < N + 1; i++) {
    long long A = x[i];
    long long OA = A != 0 ? C - A : 0;
    int j = i != 0 ? g[i - 1] : g[N];
    long long B = x[j];
    long long OB = B;
    long long get_cal = sum_A[i] + sum_B[j];
    long long lost_cal = min(2 * OA + OB, 2 * OB + OA);
    if (max < get_cal - lost_cal) {
      max = get_cal - lost_cal;
    }
  }
  cout << max << endl;
}
