#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
long long dp[maxn] = {0}, dp1[maxn] = {0};
long long max(long long x, long long y) { return x > y ? x : y; }
long long min(long long x, long long y) { return x < y ? x : y; }
struct p {
  long long x, v;
} a[maxn];
bool cmp(p a, p b) { return a.x < b.x; }
int main() {
  int n;
  long long c;
  cin >> n >> c;
  for (int i = 0; i < n; i++) cin >> a[i].x >> a[i].v;
  sort(a, a + n, cmp);
  for (int i = 0; i < n; i++) {
    if (i == 0)
      dp[i] = a[i].v - a[i].x;
    else
      dp[i] = dp[i - 1] + a[i].v - (a[i].x - a[i - 1].x);
  }
  for (int i = n - 1; i >= 0; i--) {
    if (i == n - 1)
      dp1[i] = max(dp1[i], a[i].v - c + a[i].x);
    else
      dp1[i] = max(dp1[i], dp1[i + 1] - a[i + 1].x + a[i].x + a[i].v);
  }
  long long maxx = 0;
  for (int i = 0; i < n; i++) maxx = max(dp[i], maxx);
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      maxx = max(maxx, dp1[j] + dp[i] - min(a[i].x, c - a[j].x));
  cout << maxx << endl;
}
