#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
using namespace std;
int n;
long long C;
long long dist[100005];
long long a[100005],b[100005];
int mx[100005];
int v[100005];
long long d[100005];
long long mxa[100005];
long long mxb[100005];
long long ans;
int main() {
    scanf("%d",&n);
    scanf("%lld",&C);
    for (int i=1;i<=n;i++){
        scanf("%lld",&d[i]);
        dist[i]=d[i];
        scanf("%d",&v[i]);
    }
    mxa[0]=-1e18;
    for (int i=1;i<=n;i++){
        a[i]=a[i-1]+v[i]-d[i]+d[i-1];
        mxa[i]=max(mxa[i-1],a[i]);
    }
    mxb[n+1]=-1e18;
    d[n+1]=C;
    for (int i=n;i>=1;i--){
        b[i]=b[i+1]+v[i]+d[i]-d[i+1];
        mxb[i]=max(mxb[i+1],b[i]);
    }
    reverse(b+1,b+n+1);
    reverse(mxb+1,mxb+n+1);
    dist[n+1]=C;
    for (int i=0;i<=n;i++){
        ans=max(ans,a[i]-dist[i]+mxb[n-i]);
        ans=max(ans,b[i]-C+dist[n-i+1]+mxa[n-i]);
    }
    printf("%lld",ans);
    return 0;
}