#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)

signed main(){
	int n,c;cin>>n>>c;
	vector<int> x(n),v(n),s(n+1,0),a(n+1,0),b(n+1,0);
	rep(i,n)cin>>x[i]>>v[i];
	rep(i,n){
	s[i+1]=s[i]+v[i];
	a[i+1]=max(a[i],s[i]-2*x[i]);
	b[i+1]=max(b[i],s[i]-x[i]);
	}
	int ans=b[n],a0=0,b0=0;
	for(int i=n-1;i>=1;i++){
		a0=max(a0,s[n]-s[i]+2*(c-x[i]));
		b0=max(b0,s[n]-s[i]+(c-x[i]));
		ans=max(ans,a[i-1]+b0,b[i-1]+a0);
	}
	cout<<ans<<endl;

}
