#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long n, c, a[100010], v[100010], pr[100010], s[100010], ans;
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  cin >> n >> c;
  for (long long i = 1; i <= n; i++) cin >> a[i] >> v[i];
  for (long long i = n; i >= 1; i--) s[i] = s[i + 1] + v[i];
  for (long long i = 1; i <= n; i++) pr[i] = pr[i - 1] + v[i];
  for (long long i = 1; i <= n; i++)
    pr[i] -= a[i], pr[i] = max(pr[i], pr[i - 1]);
  ans = max(ans, pr[n]);
  for (long long b = 2; b <= n; b++)
    ans = max(ans, s[b] + pr[b - 1] - 2 * (c - a[b]));
  for (long long i = 1; i <= n; i++) pr[i] = pr[i - 1] + v[i];
  for (long long i = 1; i <= n; i++)
    pr[i] -= 2 * a[i], pr[i] = max(pr[i], pr[i - 1]);
  ans = max(ans, pr[n]);
  for (long long b = 2; b <= n; b++)
    ans = max(ans, s[b] + pr[b - 1] - (c - a[b]));
  cout << ans;
}
