#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
#define N 100000 + 5

int n, V[N];
LL c, ans, Max_1[N], _Max_1[N], Max_2[N], _Max_2[N], X[N], Sum_1[N], Sum_2[N];

int main()
{
	scanf("%d%lld", &n, &c);
	for (int i = 1; i <= n; i ++)
		scanf("%lld%d", X + i, V + i);
	for (int i = 1; i <= n; i ++)
	{
		Sum_1[i] = Sum_1[i - 1] + V[i] - (X[i] - X[i - 1]);
		Max_1[i] = max(Max_1[i - 1], Sum_1[i]);
		_Max_1[i] = max(_Max_1[i - 1], Sum_1[i] - X[i]);
	}
	X[n + 1] = c;
	for (int i = n; i; i --)
	{
		Sum_2[i] = Sum_2[i + 1] + V[i] - (X[i + 1] - X[i]);
		Max_2[i] = max(Max_2[i + 1], Sum_2[i]);
		_Max_2[i] = max(_Max_2[i + 1], Sum_2[i] - (c - X[i]));
	}
	for (int i = 0; i <= n; i ++)
		ans = max(ans, max(Max_1[i] + _Max_2[i + 1], _Max_1[i] + Max_2[i + 1]));//, printf("%lld %lld, %lld %lld\n", Max_1[i], _Max_1[i], Max_2[n - i + 1], _Max_2[n - i + 1]);
	printf("%lld\n", ans);
	return 0;
}