#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
    ll N, C;
    cin >> N >> C;
    pair<ll, ll> sushi[N];
    for(ll i = 0; i < N; i++) cin >> sushi[i].first >> sushi[i].second;
    ll mae = 0;
    ll po[N + 1] = {}, yo[N + 1] = {};
    for(ll i = 0; i < N; i++){
        po[i + 1] = po[i] + sushi[i].second - (sushi[i].first - mae);
        mae = sushi[i].first;
    }
    mae = C;
    for(ll i = 0; i < N; i++){
        yo[i + 1] = yo[i] + sushi[N - i - 1].second - (mae - sushi[N - i - 1].first);
        mae = sushi[N - i - 1].first;
    }
    ll a = 0, c = 0, b = 0, d = 0, e = 0, f = 0;
    for(ll i = 0; i < N; i++){
        if(sushi[i].first <= (C + 1) / 2){
            e = max(e, po[i + 1]);
            if(b < po[i + 1] - sushi[i].first) b = po[i + 1] - sushi[i].first;
        }
        a = max(a, po[i + 1]);
    }
    for(ll i = N - 1; 0 <= i; i--){
        if(sushi[i].first > (C + 1) / 2){
            f = max(yo[N - i], f);
            if(d < yo[N - i] - (C - sushi[i].first)) d = yo[N - i] - (C - sushi[i].first);
        }
        c = max(c, yo[N - i]);
    }
    ll ans = 0;
    cout << max<ll>(ans, max(max(a, c), max(b + f, d + e))) << endl;
    return 0;
}