#include <bits/stdc++.h>
using namespace std;
constexpr long long gcd(long long a, long long b){return b ? gcd(b, a % b) : a;}
constexpr long long lcm(long long a, long long b){return a / gcd(a, b) * b;}
constexpr int INF = 1e9, MOD = INF + 7, around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
constexpr int mod_pow(long long x, long long n, const int mod){long long ret=1;while(n){if(n&1)(ret*=x)%=mod;(x*=x)%=mod;n>>=1;}return ret;}
template<int n> struct Factorial{long long arr[n+1],ary[n+1];constexpr Factorial():arr(),ary(){arr[0]=1;ary[0]=1;for(int i=0;i<n;i++){arr[i+1]=arr[i]*(i+1)%MOD;ary[i+1]=mod_pow(arr[i+1],MOD-2,MOD);}}}; constexpr Factorial<1010> fact;
constexpr long long comb(int a, int b){if(a < b) return 0LL;if(!a or !b) return 1LL; long long pos = fact.arr[a], pot = fact.ary[a - b], por = fact.ary[b]; return pos * pot % MOD * por % MOD;}
constexpr int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
constexpr long double PI = abs(acos(-1));
constexpr int sqrtN = 512, logN = 32;
constexpr long long LINF=1e18;

struct SegmentTree{
	vector<long long> seg;
	int sz = 1;
	
	SegmentTree(int n){
		while(sz < n) sz *= 2;
		seg.assign(sz * 2, -LINF);
	}
	
	void update(int k, long long x){
		k += sz - 1;
		seg[k] = x;
		
		while(k){
			k = (k - 1) / 2;
			seg[k] = max(seg[2 * k + 1], seg[2 * k + 2]);
		}
	}
	
	long long get(int a, int b){
		return get(a, b, 0, 0, sz);
	}
	
	long long get(int a, int b, int k, int l, int r){
		if(b<=l||r<=a) return 0;
		if(a<=l&&r<=b) return seg[k];
		
		return max(get(a, b, 2 * k + 1, l, (l + r) / 2), get(a, b, 2 * k + 2, (l + r) / 2, r));
	}
};

int main(){
	long long n, l; cin >> n >> l; vector<long long> a(n + 10, 0), b(n + 10, 0);
	for(int i = 1; i <= n; i++) cin >> a[i] >> b[i]; a[n + 1] = l; a[0] = 0;
	
	vector<long long> A(n + 10, 0), B(n + 10, 0);
	for(int i = 1; i <= n; i++)	A[i] = A[i - 1] + b[i];
	for(int i = n; i >= 1; i--)	B[i - 1] = B[i] + b[i];
	
	long long ma = 0;
	for(int i = 0; i <= n; i++) A[i] -= a[i];
	for(int i = 0; i <= n; i++) B[i] -= l - a[i + 1];
	for(int i = 0; i <= n; i++) ma = max(ma, A[i]);
	for(int i = 0; i <= n; i++) ma = max(ma, B[i]);
	for(int i = 0; i <= n; i++) A[i] -= a[i];
	
	SegmentTree seg(n + 10);
	for(int i = 0; i <= n; i++) seg.update(i, B[i]);
	for(int i = 0; i <= n; i++) ma = max(ma, A[i] + seg.get(i + 1, n + 1));
	SegmentTree seg2(n + 10);
	for(int i = 0; i <= n; i++) seg2.update(i, A[i] + a[i]);
	for(int i = 0; i <= n; i++) ma = max(ma, B[i] - (l - a[i + 1]) + seg2.get(0, i));
	
	cout << ma << endl;
	return 0;
}
