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

#include <cmath>

#include <string>

#include <algorithm>

#include <set>

#include <vector>

#include <map>

#include <list>

#include <stack>

#include <cstdio>

#include <cstring>

#include <cstdlib>

#include <queue>

#define mkp(a, b) make_pair(a, b)

#define pb(t) push_back(t)

#define ft first

#define sc second

#define pt(num) cout << num << "\n"

#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD

#define max(a, b) ((a)>(b) ? (a):(b))

#define min(a, b) ((a)<(b) ? (a):(b))

#define chmax(a, b) (a<b ? a=b : 0)

#define chmin(a, b) (a>b ? a=b : 0)

#define INF 1000000000000000000

#define MOD 1000000007LL

#define MAX 101010

using namespace std;

typedef long long ll;

typedef pair<ll, ll> P;

typedef map<ll, ll> Map;









int main(void) {

    ll N, C;

    cin >> N >> C;

    ll x[MAX], v[MAX];

    ll s[MAX]={};   //先頭からのカロリーの累積和

    ll r[MAX]={};   //後ろからのカロリーの累積和

    ll si[MAX]={};  //si[i]:i番目まででs[k]-x[k]が最大となるような位置k (k<=i)

    ll ssi[MAX]={}; //ssi[i]:i番目まででs[k]-x[k]*2が最大となるような位置k (k<=i)

    ll i;

    

    x[0]=0; v[0]=0;

    for(i=1; i<=N; i++) cin >> x[i] >> v[i];

    x[N+1]=C; v[N+1]=0;

    

    for(i=1; i<=N; i++) s[i]=s[i-1]+v[i];

    for(i=N; i>=1; i--) r[i]=r[i+1]+v[i];

    

    ll mx=0, mi=0;

    for(i=1; i<=N; i++) {       //si[i]を求める

        if(s[i]-x[i]>mx) {

            mx=s[i]-x[i];

            mi=i;

        }

        si[i]=mi;

    }

    

    mx=0; mi=0;

    for(i=1; i<=N; i++) {       //ssi[i]を求める

        if(s[i]-x[i]*2>mx) {

            mx=s[i]-x[i]*2;

            mi=i;

        }

        ssi[i]=mi;

    }

    

    ll ans=0;

    for(ll b=1; b<=N+1; b++) {

        chmax(ans, s[si[b-1]]-x[si[b-1]]+r[b]-(C-x[b])*2);  //OA+2OBの場合

        chmax(ans, s[ssi[b-1]]-x[ssi[b-1]]*2+r[b]-(C-x[b]));//2OA+OBの場合

    }

    pt(ans);

}








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

#define ft first

#define sc second

#define lb lower_bound

#define ub upper_bound

#define pb push_back

#define pt(sth) cout << sth << "\n"

#define chmax(a, b) {if(a<b) a=b;}

#define chmin(a, b) {if(a>b) a=b;}

#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD

using namespace std;

typedef long long ll;

typedef pair<ll, ll> P;

static const ll INF=1e18;

static const ll MAX=1e5+7;

static const ll MOD=1e9+7;

ll max(ll a, ll b) {return a>b?a:b;}

ll min(ll a, ll b) {return a<b?a:b;}







int main(void) {

  ll N, C;

  cin >> N >> C;

  ll i;

  ll x[MAX], v[MAX];

  ll s[MAX]={}, r[MAX]={};

  ll si[MAX], ssi[MAX];

  

  x[0]=0; v[0]=0; x[N+1]=C; v[N+1]=0;

  for(i=1; i<=N; i++) cin >> x[i] >> v[i];

  

  for(i=1; i<=N; i++) s[i]=s[i-1]+v[i];

  for(i=N; i>=1; i--) r[i]=r[i+1]+v[i];

  

  ll mx=0, id=0;

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

    if(mx<s[i]-x[i]) {

      mx=s[i]-x[i];

      id=i;

    }

    si[i]=id;

  }

  

  mx=0; id=0;

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

    if(mx<s[i]-x[i]*2) {

      mx=s[i]-x[i]*2;

      id=i;

    }

    ssi[i]=id;

  }

  

  ll ans=0;

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

    chmax(ans, s[si[i-1]]-x[si[i-1]]+r[i]-(C-x[i])*2);

    chmax(ans, s[ssi[i-1]]-x[ssi[i-1]]*2+r[i]-(C-x[i]));

  }

  

  pt(ans);

}