#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const double PI = acos(-1);
const double ERR = 1e-10;
long long sum1[maxn], sum2[maxn];
long long max1[maxn], max2[maxn], max3[maxn], max4[maxn];
long long x[maxn], v[maxn];
int main() {
  ios::sync_with_stdio(false);
  int n;
  long long c;
  long long ans = -LL_INF;
  cin >> n >> c;
  x[n + 1] = c;
  for (int i = 1; i <= n; i++) cin >> x[i] >> v[i];
  for (int i = 1; i <= n; i++) sum1[i] = sum1[i - 1] + v[i] - (x[i] - x[i - 1]);
  for (int i = n; i >= 1; i--) sum2[i] = sum2[i + 1] + v[i] - (x[i + 1] - x[i]);
  for (int i = 1; i <= n; i++) max1[i] = max(max1[i - 1], sum1[i] - x[i]);
  for (int i = n; i >= 1; i--) max2[i] = max(max2[i + 1], sum2[i] - (c - x[i]));
  for (int i = 1; i <= n; i++) max3[i] = max(max3[i], sum1[i]);
  for (int i = 1; i <= n; i++) max4[i] = max(max4[i], sum2[i]);
  ans = max(ans, max3[n]);
  ans = max(ans, max4[1]);
  for (int i = 1; i <= n; i++) ans = max(ans, max4[i] + max1[i - 1]);
  for (int i = 1; i <= n; i++) ans = max(ans, max3[i] + max2[i + 1]);
  cout << ans << endl;
  return 0;
}
