#include <bits/stdc++.h>
#define Maxn 200007
using namespace std;
int n;
long long c,dis[Maxn],sum1[Maxn],sum2[Maxn];
long long mx1[Maxn],mx2[Maxn];
int a[Maxn];
long long ans=0;
int main()
{
	scanf("%d",&n);
	scanf("%lld",&c);
	for (int i=1;i<=n;i++)
	{
		scanf("%lld",&dis[i]);
		scanf("%d",&a[i]);
	}
	for (int i=1;i<=n;i++)
		sum1[i]=sum1[i-1]+a[i];
	for (int i=n;i;i--)
		sum2[i]=sum2[i+1]+a[i];
	for (int i=1;i<=n;i++)
		mx1[i]=max(mx1[i-1],sum1[i]-dis[i]);
	for (int i=n;i;i--)
		mx2[i]=max(mx2[i+1],sum2[i]-c+dis[i]);
	for (int i=1;i<=n;i++)
	{
		ans=max(ans,sum1[i]-dis[i]);
		ans=max(ans,sum2[i]-c+dis[i]);
	}
	for (int i=1;i<=n;i++)
		ans=max(ans,sum1[i]-dis[i]-dis[i]+mx2[i+1]);
	for (int i=n;i;i--)
		ans=max(ans,sum2[i]-c+dis[i]-c+dis[i]+mx1[i-1]);
	printf("%lld\n",ans);
	return 0;
}
