#include<bits/stdc++.h>
using namespace std;
struct qwe{long long x,v;}a[100010];
long long n,c,nx,nv,ans,fl[100010],fr[100010],ml[100010],mr[100010];
long long read()
{
	char ch=getchar();long long Num=0,F=1;
	while(!isdigit(ch)){if(ch=='-') F=-1;ch=getchar();}
	while(isdigit(ch)){Num=(Num<<1)+(Num<<3)+ch-'0';ch=getchar();}
	return Num*F;
}
bool my(qwe g,qwe h)
{return g.x<h.x;}
int main()
{
	n=read();c=read();
	for(int i=1;i<=n;i++) a[i].x=read(),a[i].v=read();
	sort(a+1,a+1+n,my);a[n+1].x=c;
	for(int i=1;i<=n;i++) fl[i]=fl[i-1]+a[i].v+a[i-1].x-a[i].x,ml[i]=max(ml[i-1],fl[i]);
	for(int i=n;i>=1;i--) fr[n-i+1]=fr[n-i]+a[i].v+a[i].x-a[i+1].x,mr[i]=max(mr[n-i],fr[n-i+1]);
	ans=max(ml[n],mr[n]);
	for(int i=1;i<=n;i++)
	{
		if(fl[i]>a[i].x) ans=max(ans,mr[n-i]);
		if(fr[i]>c-a[n-i+1].x) ans=max(ans,ml[n-i]);
	}
	cout<<ans<<endl;
	return 0;
}