#include <bits/stdc++.h>
using namespace std;
long power(long base, long exponent, long mod) {
  if (exponent % 2) {
    return power(base, exponent - 1, mod) * base % mod;
  } else if (exponent) {
    long root_ans = power(base, exponent / 2, mod);
    return root_ans * root_ans % mod;
  } else {
    return 1;
  }
}
ostream &operator<<(ostream &os, __int128_t value) {
  if (ostream::sentry(os)) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[64];
    char *d = end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = end(buffer) - d;
    if (os.rdbuf()->sputn(d, len) != len) {
      os.setstate(ios_base::badbit);
    }
  }
  return os;
}
istream &operator>>(istream &is, __int128_t &value) {
  string in;
  is >> in;
  value = 0;
  for (const char &c : in) {
    if ('0' <= c && c <= '9') value = 10 * value + (c - '0');
  }
  if (in[0] == '-') value *= -1;
  return is;
}
struct sushi {
  __int128_t position, calorie;
  bool operator<(const __int128_t &another) const { return position < another; }
  bool operator>(const __int128_t &another) const { return position > another; }
};
signed main() {
  __int128_t N;
  __int128_t C;
  cin >> N >> C;
  vector<sushi> sushis[2];
  sushi sushis_array[N];
  sushis[1].push_back({C, 0});
  __int128_t ans = -C;
  for (__int128_t i = 0; i < N; i++) {
    cin >> sushis_array[i].position >> sushis_array[i].calorie;
    if (sushis_array[i].position * 2 <= C) {
      sushis[0].push_back(sushis_array[i]);
    } else {
      sushis[1].push_back(
          {C - sushis_array[i].position, sushis_array[i].calorie});
    }
    ans += sushis_array[i].calorie;
  }
  sushis[1].push_back({0, 0});
  reverse((sushis[1]).begin(), (sushis[1]).end());
  ans = max(ans, __int128_t(0));
  __int128_t sushi_cumulative_sum = 0;
  for (__int128_t i = 0; i < N; i++) {
    sushi_cumulative_sum += sushis_array[i].calorie;
    ans = max(ans, sushi_cumulative_sum - sushis_array[i].position);
  }
  sushi_cumulative_sum = 0;
  for (__int128_t i = N - 1; i >= 0; i--) {
    sushi_cumulative_sum += sushis_array[i].calorie;
    ans = max(ans, sushi_cumulative_sum - (C - sushis_array[i].position));
  }
  __int128_t sushi_cumulative_sum_0 = 0,
             sushi_cumulative_sums_0[sushis[1].size()];
  __int128_t sushi_cumulative_sum_1 = 0,
             sushi_cumulative_sums_1[sushis[1].size()];
  for (__int128_t i = 0; i < sushis[0].size(); i++) {
    sushi_cumulative_sum_0 += sushis[0][i].calorie;
    sushi_cumulative_sums_0[i] = sushi_cumulative_sum_0;
  }
  for (__int128_t i = 0; i < sushis[1].size(); i++) {
    sushi_cumulative_sum_1 += sushis[1][i].calorie;
    sushi_cumulative_sums_1[i] = sushi_cumulative_sum_1;
  }
  __int128_t sushi_cumulative_sums_0_double_max = 0,
             sushi_cumulative_sums_0_double_maxs[sushis[0].size()];
  __int128_t sushi_cumulative_sums_1_double_max = 0,
             sushi_cumulative_sums_1_double_maxs[sushis[1].size()];
  for (__int128_t i = 0; i < sushis[0].size(); i++) {
    sushi_cumulative_sums_0_double_max =
        max(sushi_cumulative_sums_0_double_max,
            sushi_cumulative_sums_0[i] - sushis[0][i].position * 2);
    sushi_cumulative_sums_0_double_maxs[i] = sushi_cumulative_sums_0_double_max;
  }
  for (__int128_t i = 0; i < sushis[1].size(); i++) {
    sushi_cumulative_sums_1_double_max =
        max(sushi_cumulative_sums_1_double_max,
            sushi_cumulative_sums_1[i] - sushis[1][i].position * 2);
    sushi_cumulative_sums_1_double_maxs[i] = sushi_cumulative_sums_1_double_max;
  }
  sushi_cumulative_sum_0 = 0, sushi_cumulative_sum_1 = 0;
  for (__int128_t i = 0; i < sushis[1].size(); i++) {
    sushi_cumulative_sum_1 += sushis[1][i].calorie;
    ans = max(ans, sushi_cumulative_sum_1 - sushis[1][i].position +
                       sushi_cumulative_sums_0_double_maxs
                           [lower_bound((sushis[0]).begin(), (sushis[0]).end(),
                                        sushis[1][i].position) -
                            sushis[0].begin() - 1]);
  }
  for (__int128_t i = 0; i < sushis[0].size(); i++) {
    sushi_cumulative_sum_0 += sushis[0][i].calorie;
    ans = max(ans, sushi_cumulative_sum_0 - sushis[0][i].position +
                       sushi_cumulative_sums_1_double_maxs
                           [lower_bound((sushis[1]).begin(), (sushis[1]).end(),
                                        sushis[0][i].position) -
                            sushis[1].begin() - 1]);
  }
  cout << ans << endl;
}
