#include<bits/stdc++.h>
#define maxn 102030

using namespace std;
typedef long long ll;
ll ans,n,k,a[maxn],b[maxn],s,t,x[maxn],y[maxn],z[maxn],w[maxn],C;

int main()
{
    cin >> n >> C;
    for (int i=1;i<=n;i++) scanf("%lld%lld",&a[i],&b[i]); a[n+1]=C;
    for (int i=1;i<=n;i++)
    {
        s+=b[i]-(a[i]-a[i-1]);
        t+=b[i]-(a[i]-a[i-1])*2;
        ans=max(ans,s);
        x[i]=max(x[i-1],s); y[i]=max(y[i-1],t);
    }
    s=0; t=0;
    for (int i=n;i>=1;i--)
    {
        s+=b[i]-(a[i+1]-a[i]);
        t+=b[i]-(a[i+1]-a[i])*2;
        ans=max(ans,s);
        z[i]=max(z[i+1],s); w[i]=max(w[i+1],t);
    }
    for (int i=1;i<n;i++) ans=max(ans,max(y[i]+z[i+1],x[i]+w[i+1]));
    cout << ans << endl;
}
