//### In The Name Of GOD ###

#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;

const int MOD = 1000000007;
const int INF = 30 * 1000 + 20;
const int MAXN = 100 * 1000 + 20;
const int MLOG = 18;
const int NMAX = 60;

#define int ll
#define pb push_back
#define pp pop_back
#define X first
#define Y second
#define IO ios_base::sync_with_stdio(false);
#define sz(a) (int)(a.size())
#define ct(x) const_cast<const int&>(x)


int all[2];
int prf[2][MAXN];
int ap[2][MAXN];

signed main(){
	int n, ans = 0, C;
	cin >> n >> C;
	vector< pair<int,int> > vec[2];	
	vec[0].pb({0, 0});
	vec[1].pb({0, 0});
	for (int i = 0;i < n; i++){
		int x , v;
		cin >> x >> v;
		vec[0].pb({x, v});
		vec[1].pb({C-x,v});
	}
	sort(vec[0].begin(),vec[0].end());
	sort(vec[1].begin(),vec[1].end());
	for(int i = 1; i <= n; i++){
		prf[0][i] = prf[0][i-1] - vec[0][i].X + vec[0][i-1].X + vec[0][i].Y;
		ap[0][i] = max(ap[0][i-1], prf[0][i] - vec[0][i].X);
//		cout << ap[0][i]  << " 1 " << prf[0][i]  - vec[0][i].X << ' '  << endl;
	}
	for(int i = 1; i <= n; i++){
		prf[1][i] = prf[1][i-1] - vec[1][i].X + vec[1][i-1].X + vec[1][i].Y;
		ap[1][i] = max(ap[1][i-1], prf[1][i] - vec[1][i].X);
//	cout << ap[1][i]  << " 2 " << prf[1][i] << ' ' << endl;
}
	for(int i = 1; i <= n; i++){
		all[0] += -vec[0][i].X + vec[0][i-1].X + vec[0][i].Y;
		ans = max(ans, all[0] + ap[1][n-i]);
//		cout << all[0]  << " 3 " << vec[0][i].Y << ' ' << endl;
	}
//	cout << endl;
	for(int i = 1; i <= n; i++){
		all[1] += -vec[1][i].X + vec[1][i-1].X + vec[1][i].Y;
		ans = max(ans, all[1] + ap[0][n-i]);
//		cout << all[1]  << " 4 "  << vec[1][i].Y << ' ' << endl;
	}
	cout << ans;
}
//      ___           ___           ___           ___           ___           ___           ___          _____
//     /__/\         /  /\         /__/\         /  /\         /__/\         /__/\         /  /\        /  /::\
//    |  |::\       /  /::\        \  \:\       /  /::\       |  |::\       |  |::\       /  /::\      /  /:/\:\
//    |  |:|:\     /  /:/\:\        \__\:\     /  /:/\:\      |  |:|:\      |  |:|:\     /  /:/\:\    /  /:/  \:\
//  __|__|:|\:\   /  /:/  \:\   ___ /  /::\   /  /:/~/::\   __|__|:|\:\   __|__|:|\:\   /  /:/~/::\  /__/:/ \__\:|
// /__/::::| \:\ /__/:/ \__\:\ /__/\  /:/\:\ /__/:/ /:/\:\ /__/::::| \:\ /__/::::| \:\ /__/:/ /:/\:\ \  \:\ /  /:/
// \  \:\~~\__\/ \  \:\ /  /:/ \  \:\/:/__\/ \  \:\/:/__\/ \  \:\~~\__\/ \  \:\~~\__\/ \  \:\/:/__\/  \  \:\  /:/
//  \  \:\        \  \:\  /:/   \  \::/       \  \::/       \  \:\        \  \:\        \  \::/        \  \:\/:/
//   \  \:\        \  \:\/:/     \  \:\        \  \:\        \  \:\        \  \:\        \  \:\         \  \::/
//    \  \:\        \  \::/       \  \:\        \  \:\        \  \:\        \  \:\        \  \:\         \__\/
//     \__\/         \__\/         \__\/         \__\/         \__\/         \__\/         \__\/
//      ___           ___                       ___
//     /  /\         /__/\        ___          /__/\
//    /  /::\       |  |::\      /  /\         \  \:\
//   /  /:/\:\      |  |:|:\    /  /:/          \  \:\
//  /  /:/~/::\   __|__|:|\:\  /__/::\      _____\__\:\
// /__/:/ /:/\:\ /__/::::| \:\ \__\/\:\__  /__/::::::::\
// \  \:\/:/__\/ \  \:\~~\__\/    \  \:\/\ \  \:\~~\~~\/
//  \  \::/       \  \:\           \__\::/  \  \:\  ~~~
//   \  \:\        \  \:\          /__/:/    \  \:\
//    \  \:\        \  \:\         \__\/      \  \:\
//     \__\/         \__\/                     \__\/

Measured memory_bytes: 6756