#include<bits/stdc++.h>
using namespace std;
const int maxn=100000+10;
long long int a[maxn],b[maxn],x[maxn],y[maxn]; 
long long int n,m,max1;
int main()
{
    scanf("%lld%lld",&n,&m);
    for(long long int i=1;i<=n;i++)
    {
        scanf("%lld%lld",&x[i],&y[i]);
        a[i]=a[i-1]+x[i-1]-x[i]+y[i];
    }
    x[n+1]=m;
    for(long long int i=n;i>=1;i--)
        b[i]=b[i+1]+x[i]-x[i+1]+y[i];
    for(long long int i=2;i<=n;i++)
        a[i]=max(a[i],a[i-1]);
    for(long long int i=n-1;i>=1;i--)
        b[i]=max(b[i],b[i+1]);
    for(long long int i=1;i<=n;i++)
    {
        max1=max(max1,a[i]);
        max1=max(max1,b[i]);
        max1=max(max1,a[i]+b[i+1]-x[i]);
        max1=max(max1,b[i]-(m-x[i])+a[i-1]);
    }
    printf("%d",max1);
    return 0;
}