#include <bits/stdc++.h>
constexpr int MAX_N = 100000;
int N;
long long C;
long long x[MAX_N], v[MAX_N];
int main() {
  std::cin >> N >> C;
  for (int i = 0; i < N; ++i) {
    std::cin >> x[i] >> v[i];
  }
  long long ans = 0;
  for (int i = 0; i < N; ++i) {
    long long tmp, ptmp;
    long long max = 0;
    long long pos = 0;
    for (int j = 0; j < N; ++j) {
      int k = (i + j) % N;
      if (j != 0) {
        tmp = ptmp + v[k] - std::min(abs(x[k] - pos), C - abs(x[k] - pos));
        pos = x[k];
      } else {
        tmp = v[k] - std::min(x[k], C - x[k]);
        pos = x[k];
      }
      max = std::max(max, tmp);
      ptmp = tmp;
    }
    ans = std::max(ans, max);
    max = 0, pos = 0, tmp = 0, ptmp = 0;
    for (int j = 0; j < N; ++j) {
      int k = (i - j + N) % N;
      if (j != 0) {
        tmp = ptmp + v[k] - std::min(abs(x[k] - pos), C - abs(x[k] - pos));
        pos = x[k];
      } else {
        tmp = v[k] - std::min(x[k], C - x[k]);
        pos = x[k];
      }
      max = std::max(max, tmp);
      ptmp = tmp;
    }
    ans = std::max(ans, max);
  }
  std::cout << ans << std::endl;
  return 0;
}
