#include <bits/stdc++.h>
#define maxn 100010
#define ll long long
struct arr
{
	ll x,y;
}a[maxn];
int n,i;
long long c,f[maxn]={0},g[maxn]={0},ans=0,sum=0;
int main()
{
	scanf("%d%lld",&n,&c);
	for (i=1;i<=n;i++)
		scanf("%lld%lld",&a[i].x,&a[i].y);
	for (i=1;i<=n;i++)
	{
		sum+=a[i].y;
		f[i]=sum-a[i].x*2LL;
	}
	sum=0;
	for (i=n;i>=1;i--)
	{
		sum+=a[i].y;
		g[i]=sum-(c-a[i].x)*2LL;
	}
	for (i=1;i<=n;i++)
		if (f[i]<f[i-1]) f[i]=f[i-1];
	for (i=n;i>=1;i--)
		if (g[i]<g[i+1]) g[i]=g[i+1];
	sum=0;
	for (i=1;i<=n;i++)
	{
		sum+=a[i].y;
		if (sum-a[i].x+g[i+1]>ans) ans=sum-a[i].x+g[i+1];
	}
	sum=0;
	for (i=n;i>=1;i--)
	{
		sum+=a[i].y;
		if (sum-c+a[i].x+f[i-1]>ans) ans=sum-c+a[i].x+f[i-1];
	}
	printf("%lld",ans);
	return 0;
}