#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstring>
#include <iostream>
using namespace std;
#define LL long long
const int maxN=1e5+7;
LL a[maxN],b[maxN],x[maxN],v[maxN];
int main()
{
    LL n,c;
    scanf("%lld %lld",&n,&c);
    for(int i=1;i<=n;i++)
        scanf("%lld %lld",&x[i],&v[i]);
    for(LL i=1;i<=n;i++)
        a[i]=a[i-1]+v[i]-(x[i]-x[i-1]);
    x[n+1]=c;
    for(LL i=n;i>=1;i--)
        b[i]=b[i+1]+v[i]-(x[i+1]-x[i]);
    for(LL i=2;i<=n;i++)
    {
        a[i]=max(a[i-1],a[i]);
    }
    for(LL i=n-1;i>=1;i--)
    {
        b[i]=max(b[i],b[i+1]);
    }
    LL ans=0;
    for(LL i=1;i<=n;i++)
    {
        ans=max(ans,a[i]-x[i]+b[i+1]);
        ans=max(ans,b[i]-(c-x[i])+a[i-1]);
        ans=max(ans,a[i]);
        ans=max(ans,b[i]);
    }
    printf("%lld\n",ans);
    return 0;
}
