#include <bits/stdc++.h>
using namespace std;
const long long LLINF = (1LL << 60);
const long long INF = (1LL << 30);
const long long MOD = 1000000007;
long long N, C;
long long X[100010] = {};
long long V[100010] = {};
long long dfs_r(long long i, long long j, long long k);
long long dfs_l(long long i, long long j, long long k);
long long dfs_l(long long i, long long j, long long k) {
  long long ret = 0;
  if (i <= 0 || i == k) {
    return 0;
  }
  if (j > 0) {
    long long next = 0;
    long long cal = V[next] - (X[next] + C - X[i]);
    ret = max(ret, dfs_r(next, 0, i) + cal);
  }
  {
    long long next = i - 1;
    if (next != k) {
      long long cal = V[next] - (X[i] - X[next]);
      ret = max(ret, dfs_l(next, j, k) + cal);
    }
  }
  return ret;
}
long long dfs_r(long long i, long long j, long long k) {
  long long ret = 0;
  if (i >= N - 1 || i == k) {
    return 0;
  }
  if (j > 0) {
    long long next = N - 1;
    long long cal = V[next] - (X[i] + C - X[next]);
    ret = max(ret, dfs_l(next, 0, i) + cal);
  }
  {
    long long next = i + 1;
    if (next != k) {
      long long cal = V[next] - (X[next] - X[i]);
      ret = max(ret, dfs_r(next, j, k) + cal);
    }
  }
  return ret;
}
signed main() {
  cin >> N >> C;
  for (long long i = 0; i < N; ++i) {
    cin >> X[i] >> V[i];
  }
  long long cand_r = dfs_r(0, 1, LLINF) + V[0] - X[0];
  long long cand_l = dfs_l(N - 1, 1, LLINF) + V[N - 1] - (C - X[N - 1]);
  long long ans = max({cand_r, cand_l, (long long)0});
  printf("%lld\n", ans);
  return 0;
}
