#include <cstdio>
#include <algorithm>
using namespace std;
#define N 100050
int n,i;
long long a[N],b[N],c[N],d[N],e[N],f[N],m;
int main()
{
	scanf("%d%lld",&n,&m);
	for (i=1;i<=n;i++) scanf("%lld%lld",&a[i],&b[i]),c[i]=m-a[i],d[i]=b[i],b[i]+=b[i-1];
	for (i=n;i>=0;i--) d[i]+=d[i+1];
	for (i=1;i<=n;i++) e[i]=max(e[i-1],b[i]-2*a[i]),f[i]=max(f[i-1],b[i]-a[i]);
	long long ans=0;
	for (i=1;i<=n+1;i++) ans=max(ans,max(e[i-1]+d[i]-c[i],f[i-1]+d[i]-2*c[i]));
	printf("%lld\n",ans);
	return 0;
}