#include <bits/stdc++.h>
using namespace std;
int vx[] = {0, 0, -1, 1};
int vy[] = {1, -1, 0, 0};
int dx[] = {1, 0, -1, 1, -1, 1, 0, -1};
int dy[] = {1, 1, 1, 0, 0, -1, -1, -1};
const long long mod = 1e9 + 7;
const int INF = INT_MAX / 2;
const int MAX = 1e9;
const int MAX_V = 10000;
int N;
long long C;
long long x[100010];
long long v[100010];
int main() {
  cin >> N >> C;
  for (int i = 0; i < N; i++) cin >> x[i] >> v[i];
  long long d[N];
  d[0] = x[0];
  for (int i = 1; i < N; i++) {
    d[i] = x[i] - x[i - 1];
  }
  long long res = 0;
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    res += v[i] - d[i];
    if (res > ans) ans = res;
  }
  res = 0;
  for (int i = N - 1; i >= 0; i--) {
    if (i == N - 1)
      res += v[i] - (C - x[i]);
    else
      res += v[i] - d[i + 1];
    if (res > ans) ans = res;
  }
  for (int i = 0; i < N; i++) {
    res = 0;
    for (int j = 0; j <= i; j++) {
      res += v[j] - d[j];
      if (res > ans) ans = res;
    }
    res -= x[i];
    for (int j = N - 1; j > i; j--) {
      if (j == N - 1)
        res += v[j] - (C - x[j]);
      else
        res += v[j] - d[j + 1];
      if (res > ans) ans = res;
    }
    res = 0;
    for (int j = N - 1; j > i; j--) {
      if (j == N - 1)
        res += v[j] - (C - x[j]);
      else
        res += v[j] - d[j + 1];
      if (res > ans) ans = res;
    }
    res -= C - x[i + 1];
    for (int j = 0; j <= i; j++) {
      res += v[j] - d[j];
      if (res > ans) ans = res;
    }
  }
  cout << ans << endl;
  return 0;
}
