#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define F first
#define S second
ll n,c,mm[100005],tm[100005],ans;
P s[100005];
int main(void){
    scanf("%lld%lld",&n,&c);
    for(int i=0;i<n;i++){
        scanf("%lld%lld",&s[i].F,&s[i].S);
    }
    ll q=0;
    for(int i=0;i<n;i++){
        ll k=s[i].F;
        q+=s[i].S;
        mm[i]=q-k;
        tm[i]=max(q-2*k,tm[i-1]);
        ans=max(mm[i],ans);
    }
    ll hm=0,sm=0;
    q=0;
    for(int i=n-1;i>=0;i--){
        ll k=c-s[i].F;
        q+=s[i].S;
        sm=q-k;
        hm=max(q-2*k,hm);
        ans=max(sm,ans);
        if(i>0){
            ans=max(ans,sm+tm[i-1]);
            ans=max(ans,hm+mm[i-1]);
        }
    }
    cout<<ans<<endl;
}