#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
long long N;
long long C;
long long x[100010];
long long v[100010];
long long sum[100010];
int main() {
  cin >> N >> C;
  long long ans = 0;
  for (long long i = 1; i < N + 1; i++) {
    cin >> x[i] >> v[i];
  }
  for (long long i = 1; i < N + 1; i++) {
    sum[i] = sum[i - 1] + v[i];
  }
  for (long long i = 1; i < N + 1; i++) {
    ans = max({ans, sum[i] - x[i], sum[N] - sum[i - 1] - (C - x[i])});
  }
  long long mx = 0;
  long long next = 0;
  long long mx2 = 0;
  long long mx3 = 0;
  long long mx4 = 0;
  for (long long i = 1; i < N + 1; i++) {
    for (long long j = i + 1; j < N + 1; j++) {
      mx = max(mx, sum[i] - x[i] + sum[N] - sum[j - 1] - (C - x[j]) * 2);
      mx2 = max(mx, sum[i] - 2 * x[i] + sum[N] - sum[j - 1] - (C - x[j]));
    }
  }
  ans = max({ans, mx, mx2});
  cout << (ans) << endl;
  return 0;
}
