#include <bits/stdc++.h>
int main() {
  int64_t N, C;
  std::cin >> N >> C;
  std::vector<int64_t> pos;
  std::vector<int64_t> cal;
  for (int i = 0; i < N; ++i) {
    int64_t x, v;
    std::cin >> x >> v;
    pos.push_back(x);
    cal.push_back(v);
  }
  std::vector<int64_t> r_sums;
  std::vector<int64_t> l_sums;
  r_sums.push_back(cal[0] - pos[0]);
  l_sums.push_back(cal[N - 1] - (C - pos[N - 1]));
  for (int i = 1; i < N; ++i) {
    r_sums.push_back(r_sums[i - 1] + cal[i] - (pos[i] - pos[i - 1]));
    l_sums.push_back(l_sums[i - 1] + cal[N - 1 - i] -
                     (pos[N - i] - pos[N - i - 1]));
  }
  int64_t r_max = *std::max_element(r_sums.begin(), r_sums.end());
  int64_t l_max = *std::max_element(l_sums.begin(), l_sums.end());
  int64_t max = 0;
  for (int i = 0; i < N - 1; ++i) {
    int64_t r_target =
        r_sums[i] + (*std::max_element(l_sums.begin(), l_sums.end() - i - 1)) -
        pos[i];
    int64_t l_target =
        l_sums[i] + (*std::max_element(r_sums.begin(), r_sums.end() - i - 1)) -
        pos[N - 1 - i];
    max = std::max({r_target, l_target, max});
  }
  std::cout << std::max({r_max, l_max, max}) << std::endl;
}
