#include<bits/stdc++.h>
using namespace std;
#define int long long
//using lint=long long int;
int n;
int c;
vector<int> x,v;
vector<int>f,g;

int inf=1e18;

void fill_vector(vector<int>a,vector<int>b){
	f.resize(n+1,0);g.resize(n+1,0);
	for(int i=0;i<n;i++){
		f[i+1]=f[i]+b[i];
	}
	for(int i=0;i<n;i++){
		g[i+1]=max(g[i],f[i+1]-a[i]);
	}
}


signed main(){
	cin>>n>>c;
	x.resize(n);
	v.resize(n);
	for(int i=0;i<n;i++){
		cin>>x[i]>>v[i];
	}

	fill_vector(x,v);
//	for(auto&& u:f)cerr<<u<<endl;
//	for(auto&& u:g)cerr<<u<<endl;
//	cerr<<endl;

	int ans=max(g[n],f[n]-min(c-x[0],x[n-1]));
		cerr<<ans<<endl;
	for(int i=0;i<n-1;i++){
		int y=g[i+1]+f[n]-f[i+1]-2*(c-x[i+1]);
		ans=max(ans,y);
	//	cerr<<y<<" "<<ans<<endl;
	}
  	cout<<endl;
	reverse(begin(x),end(x));
	reverse(begin(v),end(v));

	fill_vector(x,v);
	ans=max(ans,g[n]));

	for(int i=0;i<n-1;i++){
		int y=g[i+1]+f[n]-f[i+1]-2*(c-x[i+1]);
		ans=max(ans,y);
	//	cerr<<y<<" "<<ans<<endl;
	}
	cout<<ans<<endl;

}