// Slower C++ solution:
#include <iostream>

#include <string.h>

#include <stdio.h>

#include <map>

#include <vector>

#include <math.h>

using namespace std;



#define rep(i,a) for(int i=0; i<a; i++)

#define rrep(i,a) for(int i=a; i>=0; i--)

#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)

#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)

#define rep1(i,a) for(int i=1; i<=a; i++)



#define scnd1(a) scanf("%d", &a)

#define scnd2(a,b) scanf("%d%d", &a,&b)

#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)

#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)



#define prtd1(a) printf("%d\n", a)

#define prtd2(a,b) printf("%d %d\n", a,b)

#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)

#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)



#define mem(a,n) memset( a, n, sizeof(a))



typedef long long ll;

ll N, C, dist[100009], cal[100009], turnL[100009][2], turnR[100009][2];



int main() {

    

    cin >> N >> C;

    

    mem( turnL, 0); mem( turnR, 0);

    

    rep( i, N) cin >> dist[i] >> cal[i];

    

    // 時計回りした時の寿司iまでの差し引きカロリーの最高値計算

    ll sumcal = 0;

    rep( i, N) {

        sumcal += cal[i];

        if(i==0 && cal[i] - dist[i] > 0 ) {

            turnR[i][0] = sumcal - dist[i];

            turnR[i][1] = dist[i];

        } else {

            if ( sumcal - dist[i] <= turnR[i-1][0] ) {

                turnR[i][0] = turnR[i-1][0];

                turnR[i][1] = turnR[i-1][1];

            } else {

                turnR[i][0] = sumcal - dist[i];

                turnR[i][1] = dist[i];

            }

        }

    }

    

    // 反時計時計回りした時の寿司iまでの差し引きカロリーの最高値計算

    sumcal = 0;

    rrep( i, N-1) {

        sumcal += cal[i];

        if(i==N-1) {

            if ( cal[i] - (C-dist[i]) > 0 ) {

                turnL[i][0] = sumcal - (C-dist[i]);

                turnL[i][1] = (C-dist[i]);

            }

        } else {

            if ( sumcal - (C-dist[i]) <= turnL[i+1][0] ) {

                turnL[i][0] = turnL[i+1][0];

                turnL[i][1] = turnL[i+1][1];

            } else {

                turnL[i][0] = sumcal - (C-dist[i]);

                turnL[i][1] = (C-dist[i]);

            }

        }

    }

    

    ll maxcal = max( turnR[N-1][0], turnL[0][0]);

    

    // 反時計回りにBまで行き折り返してAまで行く場合の差し引きカロリーの最大値を全探索

    for ( int i = 1; i < N; i++ ) {

        maxcal = max( maxcal, turnL[i+1][0] - turnL[i+1][1] + turnR[i][0] );

    }

    

    // 時計回りにAまで行き折り返してBまで行く場合の差し引きカロリーの最大値を全探索

    for ( int i = 1; i < N; i++ ) {

        maxcal = max( maxcal, turnR[i-1][0] - turnR[i-1][1] + turnL[i][0] );

    }

    

    cout << maxcal << endl;

}

// Faster C++ solution for the same problem (measured speedup: 4.167639350955305x):
#include "bits/stdc++.h"

#include <iostream>

#include <string.h>

#include <stdio.h>

#include <map>

#include <vector>

#include <math.h>

#include <algorithm>

#include <queue>

#include <set>

#include <tuple>

using namespace std;



#define FOR(i,init,a) for(int i=init; i<a; i++)

#define rep(i,a) FOR(i,0,a)

#define rrep(i,a) for(int i=a; i>=0; i--)

#define rep1(i,a) for(int i=1; i<=a; i++)

#define cout1(a) cout << a << endl;

#define cout2(a,b) cout << a << " " << b << endl;

#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;

#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;

#define mem(a,n) memset( a, n, sizeof(a))

#define all(a) a.begin(),a.end()

#define chmin(a,b) a=min(a,b);

#define chmax(a,b) a=max(a,b);



typedef long long ll;

typedef long double ld;

typedef pair<int,int> pii;

const int INF = 1e9;

const int MOD = 1e9+7;

const ll LLINF = 1e18;

static const double pi = 3.141592653589793;



ll N,C;

ll X[100009], V[100009];

ll turnL[100009], turnR[100009];



int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);

    

    cin>>N>>C;

    rep(i,N) cin>>X[i]>>V[i];

    

    ll sum=0, mx=0;

    rep(i,N){

        sum+=V[i];

        chmax(mx,sum-X[i]);

        turnL[i]=mx;

    }

    

    sum=0, mx=0;

    rrep(i,N-1){

        sum+=V[i];

        chmax(mx,sum-(C-X[i]));

        turnR[i]=mx;

    }

    

    ll ans=0;

    rep(i,N){

        ll tmp=turnL[i];

        if(i<N-1) tmp+=max(0ll,turnR[i+1]-X[i]);

        chmax(ans,tmp);

    }

    

    rrep(i,N-1){

        ll tmp=turnR[i];

        if(i) tmp+=max(0ll,turnL[i-1]-(C-X[i]));

        chmax(ans,tmp);

    }

    

    cout1(ans)

}