#include <bits/stdc++.h>
using namespace std;
const long long MOD = 10e9 + 7;
const long long INF = LLONG_MAX;
const long long MAX_V = 10e3;
const double EPS = 10e-6;
const double PI = 3.14159265359;
long long n, c, x[100005], v[100005], sum[100005]{}, memo[2][100000][2],
    ans = 0;
int main() {
  cin >> n >> c;
  x[0] = 0;
  v[0] = 0;
  x[n + 1] = 0;
  v[n + 1] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> v[i];
    sum[i] = sum[i - 1] + v[i];
  }
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) memo[i][0][j] = 0;
  }
  for (int i = 1; i <= n; i++) {
    memo[0][i][0] = max(memo[0][i - 1][0], sum[i] - sum[0] - x[i]);
    memo[0][i][1] = max(memo[0][i - 1][1], sum[i] - sum[0] - x[i] * 2);
  }
  for (int i = 1; i <= n; i++) {
    memo[1][i][0] =
        max(memo[1][i - 1][0], sum[n] - sum[n - i] - (c - x[n - i + 1]));
    memo[1][i][1] =
        max(memo[1][i - 1][1], sum[n] - sum[n - i] - (c - x[n - i + 1]) * 2);
  }
  for (int i = 0; i <= n; i++) {
    ans = max(ans, max(memo[0][i][1] + memo[1][n - i][0],
                       memo[0][i][0] + memo[1][n - i][1]));
  }
  cout << ans << endl;
  return 0;
}
