#include<iostream>
#include<algorithm>

using namespace std;

int x[100'000];
int v[100'000];

int main(){
	int n, c;
	cin >> n >> c;

	for(int i = 0; i < n; ++i){
		cin >> x[i] >> v[i];
	}

	int max = -1;
	for(int j = n; j >= 0; --j){
		int cal = 0;
		int nowX = 0;
		int d = 0;
		// ちょっと反時計回り
		for(int i = 0; i <= j; ++i){
			int localD = c - x[i];
			cal += v[i] - localD + nowX;
			max = max(max, cal);
			nowX = localD;
			d += localD;
		}
		// 初期位置に戻る
		cal -= d;
		nowX = 0;
		// 時計回り
		for(int i = 0; i < n-j; ++i){
			cal += v[i] - x[i] + nowX;
			max = max(max, cal);
			nowX = x[i];
		}
	}

	cout << max << endl;
	return 0;
}