#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll n, c;
	cin >> n >> c;

	ll x[n+2], v[n+2];
	x[0] = 0;
	v[0] = 0;
	x[n+1] = 0;
	v[n+1] = 0;
	rep(i,n) cin >> x[i+1] >> v[i+1];

	ll hx[n+2];
	hx[0] = 0;
	hx[n+1] = 0;
	rep(i,n) hx[i+1] = c - x[i+1];

	ll t = 0;
	ll tv[n+1];
	tv[0] = 0;

	rep(i,n){
		t += v[i+1] - x[i+1] + x[i];
		tv[i+1] = max(tv[i], t);
	}

	ll h = 0;
	ll hv[n+2];
	hv[n+1] = 0;


	rrep(i,n){
		h += v[i+1] - hx[i+1] + hx[i+2];
		hv[i+1] = max(hv[i+2], h);
	}

	ll ans = 0;
	rep(i,n){
		ans = max(ans, tv[i+1] + max(hv[i+2]- x[i+1],0LL));
		ans = max(ans, hv[i+1] + max(tv[i] - hx[i+1],0LL));
	}

	cout << ans << endl;
}