#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<pi>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
void sonic() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void setp(const ll n) { cout << fixed << setprecision(n); }
const ll INF = 1e9 + 1;
const ll LINF = 1e18 + 1;
const ll MOD = 1e9 + 7;
const ld PI = acos(-1);
const ld EPS = 1e-11;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
void co(T e) {
  cout << e << "\n";
}
template <typename T>
void co(const vector<T>& v) {
  for (const auto& e : v) {
    cout << e << " ";
  }
  cout << "\n";
}
ll gcd(ll a, ll b) {
  if (a < b) swap(a, b);
  if (b == 0) return a;
  unsigned r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a * b / g;
}
bool prime(ll n) {
  for (ll i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return false;
  }
  return n != 1;
}
const int n = 3000;
int fac[n];
int inv[n];
ll pow(int a, int n, int mod) {
  if (n == 1) return a;
  if (n % 2 == 0) return pow(1LL * a * a % MOD, n / 2, MOD);
  return 1LL * a * pow(1LL * a * a % MOD, n / 2, MOD) % MOD;
}
void init(int n) {
  fac[0] = 1;
  for (ll(i) = (1); (i) < (n + 1); ++(i)) fac[i] = 1LL * fac[i - 1] * i % MOD;
  inv[n] = pow(fac[n], MOD - 2, MOD);
  for (ll(j) = (n - 1); (j) > (-1); --(j))
    inv[j] = 1LL * inv[j + 1] * (j + 1) % MOD;
}
int comb(ll n, ll k) {
  if (k > n) return 0;
  return 1LL * fac[n] * inv[k] % MOD * inv[n - k] % MOD;
}
pair<int, vector<int> > bfs(const vector<vector<int> >& g, int x) {
  vector<int> d(g.size(), -1);
  queue<int> q;
  q.push(x);
  int u = -1;
  d[x] = 0;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    for (auto& v : g[u]) {
      if (d[v] != -1) continue;
      d[v] = d[u] + 1;
      q.push(v);
    }
  }
  return make_pair(u, d);
}
vector<int> dist(const vector<vector<int> >& g) {
  auto p1 = bfs(g, 0);
  auto p2 = bfs(g, p1.first);
  auto p3 = bfs(g, p2.first);
  vector<int> res(g.size());
  for (ll(i) = (0); (i) < (g.size()); ++(i))
    res[i] = max(p2.second[i], p3.second[i]);
  sort(res.begin(), res.end());
  return res;
}
vector<vector<int> > readGraph() {
  int n;
  cin >> n;
  vector<vector<int> > g(n);
  for (ll(i) = (0); (i) < (n - 1); ++(i)) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
}
ll v[n], x[n], r1[n], r2[n];
int main() {
  int n, c;
  cin >> n >> c;
  for (ll(i) = (0); (i) < (n); ++(i)) cin >> x[i] >> v[i];
  ll ret = 0, pre = 0;
  for (ll(i) = (0); (i) < (n); ++(i)) {
    ret += v[i];
    chmax(pre, ret - x[i]);
    r1[i] = pre;
  }
  ll ret2 = 0, pre2 = 0;
  for (ll(i) = (0); (i) < (n); ++(i)) {
    ret2 += v[n - 1 - i];
    chmax(pre2, ret2 - (c - x[n - i - 1]));
    r2[i] = pre2;
  }
  ll ans = 0;
  for (ll(i) = (0); (i) < (n - 1); ++(i)) {
    chmax(ans, r1[i] - x[i] + r2[n - i - 2]);
    chmax(ans, r2[i] - (c - x[n - i - 1]) + r1[n - i - 2]);
  }
  chmax(ans, r1[n - 1]);
  chmax(ans, r2[n - 1]);
  co(ans);
}
