#include<cstdio>

#define Fast register
#define Maxn 100001
#define LL long long
template<class T>inline T Min(const T&x,const T&y){return x<y?x:y;}
template<class T>inline T Max(const T&x,const T&y){return x>y?x:y;}
template<class T>inline bool chkMin(T&x,const T&y){return(x>y)?(x=y,true):false;}
template<class T>inline bool chkMax(T&x,const T&y){return(x<y)?(x=y,true):false;}

LL x[Maxn];
LL v[Maxn];

struct IO{
	#define ISIZE 16384

	char IBUF[ISIZE],*IS,*IT;

	IO():IS(IBUF),IT(IBUF){}
	~IO(){}

	inline char Getchar(){return(IS==IT)&&(IT=(IS=IBUF)+fread(IBUF,1,ISIZE,stdin),IS==IT)?EOF:*IS++;}
	template<class T>inline IO&operator>>(T&x){
		Fast T s=0;Fast char c;
		do c=Getchar();while(c<48||c>57);
		do s=s*10+c-48,c=Getchar();while(c>47&&c<58);
		return(x=s,*this);
	}

	#undef ISIZE
}io;

int main(){
	Fast int N;Fast LL C;io>>N>>C;
	Fast LL sum=0;
	for(Fast int i=1;i<=N;++i)
		io>>x[i]>>v[i],sum+=v[i];
	Fast LL Ans1=0,Ans2=0;
	Fast LL pos1=0,pos2=C;
	for(Fast int i=1;i<=N;++i)
		if(x[i]-pos1<=v[i])
			Ans1+=v[i]-(x[i]-pos1),pos1=x[i];
		else break;
	for(Fast int i=N;i;--i)
		if(pos2-x[i]<=v[i])
			Ans2+=v[i]-(pos2-x[i]),pos2=x[i];
		else break;
	Fast LL Ans3=0,pos3=0,Ans4=0,pos4=C,tmp=0;
	for(Fast int i=1;i<=N;++i){
		tmp+=v[i];
		if(chkMax(Ans3,tmp-x[i]))pos3=x[i];
	}tmp=0;
	for(Fast int i=N;i;--i){
		tmp+=v[i];
		if(chkMax(Ans4,tmp-(C-x[i])))pos4=x[i];
	}Fast LL Ans=Max(Max(Ans3,Ans4),Max(Ans1,Ans2));
	if(pos1>=pos2||pos3>=pos2||pos1>=pos4||pos3>=pos4)
		chkMax(Ans,sum-Min(x[N],C-x[1]));
	if(pos1<pos2)
		chkMax(Ans,Ans1+Ans2-Min(pos1,C-pos2));
	if(pos1<pos4)
		chkMax(Ans,Ans4+Ans1-Min(pos1,C-pos4));
	if(pos3<pos2)
		chkMax(Ans,Ans3+Ans2-Min(pos3,C-pos2));
	if(pos3<pos4)
		chkMax(Ans,Ans3+Ans4-Min(pos3,C-pos4));
	return(printf("%lld\n",Ans),0);
}
