#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;



#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

ll debugFlag = false;
template<typename T> void debug(T&);
template<typename T> void debug(T&, bool);
template<typename T> void debug(vector<T>&);
template<typename T> void debug(vector<T>&, bool);
template<typename T, typename U> void debug(pair<T, U>&);
template<typename T, typename U> void debug(pair<T, U>&, bool);

template<typename T>
void debug(T& obj) {
	debug(obj, true);
}

template<typename T>
void debug(T& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << obj;
	if (lnFlag) cout << endl;
}

template<typename T>
void debug(vector<T>& obj) {
	debug(obj, true);
}

template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "[";
	rep(i, obj.size()) {
		if (i != 0) cout << ",";
		debug(obj[i], false);
	}
	cout << "]";
	if (lnFlag) cout << endl;
}

template<typename T, typename U>
void debug(pair<T, U>& obj) {
	debug(obj, true);
}

template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "(";
	debug(obj.first, false);
	cout << ",";
	debug(obj.second, false);
	cout << ")";
	if (lnFlag) cout << endl;
}

bool isPrime(ll num) {

	bool flag = true;
	for (int i = 2; i <= sqrt(num); i++) {
		if (num%i == 0) {
			flag = false;
			break;
		}
	}

	return flag;
}

void solve() {

	//右に向かってi個の寿司を食べていいとき，一番得するのはclockwise[i]個まで食べる(10^5)
	//左に向かってi個の寿司を食べていいとき，一番得するのはrevclockwise[i]個まで食べる(10^5)

	//右に向かってi個まで食べてよく，その後左に戻ってN-i個まで食べてよい(10^5)
	//左に向かってi個まで食べてよく，その後右に戻ってN-i個まで食べて良い(10^5)

	ll N, C;
	cin >> N >> C;

	vector<pair<ll, ll>> vec(N);
	rep(i, N) cin >> vec[i].first >> vec[i].second;

	vector<ll> subsum(N + 1);
	vector<ll> revsubsum(N + 1);
	rep(i, N + 1) {
		if (i == 0) subsum[i] = 0;
		else subsum[i] = subsum[i - 1] + vec[i-1].second;

		if (i == 0) revsubsum[i] = 0;
		else revsubsum[i] = revsubsum[i - 1] + vec[N - i].second;
	}

	debug(subsum);
	debug(revsubsum);

	vector<ll> clockwise(N + 1);
	ll best = 0;
	ll best_index = 0;
	rep(i, N+1) {
		if (i == 0) clockwise[i] = 0;
		else {
			if (subsum[i] - vec[i - 1].first > best) {
				best = subsum[i] - vec[i - 1].first;
				best_index = i;
			}
			clockwise[i] = best_index;
		}
	}

	vector<ll> revclockwise(N + 1);
	best = 0;
	best_index = 0;
	rep(i, N + 1) {
		if (i == 0) revclockwise[i] = 0;
		else {
			if (revsubsum[i] - C + vec[N - i].first > best) {
				best = revsubsum[i] - C + vec[N - i].first;
				best_index = i;
			}
			revclockwise[i] = best_index;
		}
	}

	debug(clockwise);
	debug(revclockwise);

	ll ans = 0;

	ll tmp, tmp2;
	rep(i, N + 1) {
		//右へ
		if (clockwise[i] == 0) tmp = 0;
		else tmp = subsum[clockwise[i]] - vec[clockwise[i]-1].first;

		ans = max(ans, tmp);

		//左へ
		if (revclockwise[N - i] == 0) tmp2 = 0;
		else tmp2 = revsubsum[revclockwise[N - i]] - C + vec[N - revclockwise[N - i]].first;

		if (clockwise[i] == 0) ans = max(ans, tmp + tmp2);
		else ans = max(ans, tmp + tmp2 - vec[clockwise[i] - 1].first);

	}

	rep(i, N + 1) {
		//左へ
		if (revclockwise[i] == 0) tmp = 0;
		else tmp = revsubsum[revclockwise[i]] - C + vec[N - revclockwise[i]].first;

		ans = max(ans, tmp);

		//右へ
		if (clockwise[N-i] == 0) tmp2 = 0;
		else tmp2 = subsum[clockwise[N - i]] - vec[clockwise[N - i] - 1].first;

		if (revclockwise[i] == 0) ans = max(ans, tmp + tmp2);
		else ans = max(ans, tmp + tmp2 - C + vec[N - revclockwise[i]].first);
	}

	cout << ans;

}


int main(int argc, char* argv[]) {
	if (argc == 2 && string(argv[1]) == "debug") debugFlag = true;
	solve();
	return 0;
}


Measured memory_bytes: 4992