#include <bits/stdc++.h>
using namespace std;
long long N, C;
long long x[100005];
int v[100005];
long long A1[100005];
long long A2[100005];
long long B1[100005];
long long B2[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];
  }
  long long sum = 0;
  long long m1 = 0;
  long long m2 = 0;
  for (int i = 1; i < N + 1; i++) {
    sum += v[i - 1];
    m1 = max(m1, sum - x[i - 1]);
    m2 = max(m2, sum - 2 * x[i - 1]);
    A1[i] = m1;
    A2[i] = m2;
  }
  sum = 0;
  m1 = 0;
  m2 = 0;
  for (int i = N; i > 0; i--) {
    sum += v[i];
    m1 = max(m1, sum - (C - x[i]));
    m2 = max(m2, sum - 2 * (C - x[i]));
    B1[i] = m1;
    B2[i] = m2;
  }
  long long ans = 0;
  for (int i = 0; i <= N; i++) {
    ans = max(ans, max(A2[i] + B1[i], A1[i] + B2[i]));
  }
  cout << ans << endl;
}
