#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
long long lcm(long long x, long long y) { return x * y / gcd(x, y); }
bool sosuu(int x) {
  bool b = 1;
  if (x == 1) b = 0;
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      b = 0;
      break;
    }
  }
  return b;
}
long long n, c;
pair<long long, long long> p[100001];
int main() {
  cin >> n >> c;
  for (int i = 0; i < n; i++) {
    cin >> p[i].first >> p[i].second;
  }
  long long ans = 0, cnt = 0, l = 0;
  for (int i = n - 1; i >= 0 && p[i].first > c / 2; i--) {
    cnt += p[i].second;
    if (i == n - 1)
      cnt -= (c - p[i].first) * 2;
    else
      cnt -= (p[i + 1].first - p[i].first) * 2;
    l = max(l, cnt);
  }
  cnt = 0;
  for (int i = 0; p[i].first <= c / 2 && i < n; i++) {
    cnt += p[i].second;
    if (i == 0)
      cnt -= p[i].first;
    else
      cnt -= (p[i].first - p[i - 1].first);
    ans = max(ans, cnt + l);
  }
  cnt = 0;
  for (int i = 0; i < n; i++) {
    cnt += p[i].second;
    if (i == 0)
      cnt -= p[i].first;
    else
      cnt -= (p[i].first - p[i - 1].first);
    ans = max(ans, cnt);
  }
  cnt = 0;
  for (int i = n - 1; i >= 0; i--) {
    cnt += p[i].second;
    if (i == n - 1)
      cnt -= (c - p[i].first);
    else
      cnt -= (p[i + 1].first - p[i].first);
    ans = max(ans, cnt);
  }
  long long r = 0;
  cnt = 0;
  for (int i = 0; i < n && p[i].first < c / 2; i++) {
    cnt += p[i].second;
    if (i == 0)
      cnt -= p[i].first * 2;
    else
      cnt -= (p[i].first - p[i - 1].first) * 2;
    r = max(r, cnt);
  }
  cnt = 0;
  for (int i = n - 1; p[i].first >= c / 2 && i >= 0; i--) {
    cnt += p[i].second;
    if (i == n - 1)
      cnt -= (c - p[i].first);
    else
      cnt -= (p[i + 1].first - p[i].first);
    ans = max(ans, cnt + r);
  }
  cout << ans << endl;
  return 0;
}
