#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 dp[100010] = {};
pair<long long, long long> turn_r = make_pair(0, -1);
pair<long long, long long> turn_l = make_pair(0, -1);
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_r2(long long i) {
  if (dp[i] != LLINF) {
    return dp[i];
  }
  if (i >= N - 1) {
    return 0;
  }
  long long ret = 0;
  long long next = i + 1;
  long long cal = V[next] - (X[next] - X[i]);
  long long cand = dfs_r2(next) + cal;
  if (ret < cand) {
    ret = cand;
    if (X[i] <= C / 2) {
      turn_r.first = cand;
      turn_r.second = i;
    }
  }
  return ret;
}
long long dfs_l2(long long i) {
  if (dp[i] != LLINF) {
    return dp[i];
  }
  if (i <= 0) {
    return 0;
  }
  long long ret = 0;
  long long next = i - 1;
  long long cal = V[next] - (X[i] - X[next]);
  long long cand = dfs_l2(next) + cal;
  if (ret < cand) {
    ret = cand;
    if (X[i] >= C / 2) {
      turn_l.first = cand;
      turn_l.second = i;
    }
  }
  return ret;
}
long long dfs_r3(long long i) {
  if (dp[i] != LLINF) {
    return dp[i];
  }
  if (i >= N - 1 || X[i] >= C / 2) {
    return 0;
  }
  long long ret = 0;
  long long next = i + 1;
  long long cal = V[next] - (X[next] - X[i]);
  long long cand = dfs_r2(next) + cal;
  if (ret < cand) {
    ret = cand;
  }
  return ret;
}
long long dfs_l3(long long i) {
  if (dp[i] != LLINF) {
    return dp[i];
  }
  if (i <= 0 || X[i] <= C / 2) {
    return 0;
  }
  long long ret = 0;
  long long next = i - 1;
  long long cal = V[next] - (X[i] - X[next]);
  long long cand = dfs_l2(next) + cal;
  if (ret < cand) {
    ret = cand;
  }
  return ret;
}
signed main() {
  cin >> N >> C;
  for (long long i = 0; i < N; ++i) {
    cin >> X[i] >> V[i];
  }
  for (long long i = 0; i < 100010; ++i) {
    dp[i] = LLINF;
  }
  long long cand_r = dfs_r2(0) + V[0] - X[0];
  for (long long i = 0; i < 100010; ++i) {
    dp[i] = LLINF;
  }
  long long cand_l = dfs_l2(N - 1) + V[N - 1] - (C - X[N - 1]);
  long long cand_r2 = 0, cand_l2 = 0;
  cand_r2 = V[0] - X[0] + turn_r.first - X[turn_r.second];
  cand_r2 += V[N - 1] - (C - X[N - 1]) + turn_l.first - (C - X[turn_l.second]);
  long long ans = max({cand_r, cand_l, cand_r2, cand_l2, (long long)0});
  printf("%lld\n", ans);
  return 0;
}
