#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const int N=1e5+5;
ll f[N][N][2],x[N*2];
int main()
{
    ll n,c,i,j,k,v[N];
    cin>>n>>c;
    for(i=1;i<=n;i++){
        scanf("%lld%lld",&x[n+1+i],&v[i]);
    }
    ll l=c-x[n+2];
    for(i=2;i<=n;i++){
        x[i]=x[n+1+i]-x[n+1+i-1];v[i]=v[n+1+i];
    }
    x[n+1]=c-x[n+2];v[1]=v[n+2];v[n+1]=0;
    for(i=1;i<=n;i++)
        x[n+1+i]+=x[n+1];
    for(j=n+1;j<=2*n+1;j++)
        for(i=j-1;i>=j-n;i--){
        f[i][j][0]=max(f[i][j][0],f[i+1][j][0]+v[i]-(x[i+1]-x[i]));
        f[i][j][0]=max(f[i][j][0],f[i+1][j][1]+v[i]-(x[j]-x[i]));
        f[i][j][1]=max(f[i][j][1],f[i][j-1][0]+v[j]-(x[j]-x[i]));
        f[i][j][1]=max(f[i][j][1],f[i][j-1][1]+v[j]-(x[j]-x[j-1]));
    }
    ll ans=0;
    for(i=1;i<=n+1;i++){
        ans=max(ans,f[i][i+n][0]);
        ans=max(ans,f[i][i+n][1]);
    }
    cout<<ans<<endl;

    return 0;
}