#include <bits/stdc++.h>
using namespace std;
int N;
long long C, x[100005], v[100005], sum[100005], sumb[100005];
long long maxi[100005], maxidb[100005], ans;
int main()
{
#ifdef _noname
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%d%lld", &N, &C);
	for (int i = 1; i <= N; i++) scanf("%lld%lld", x + i, v + i);
	sum[0] = sumb[N + 1] = 0;
	for (int i = 1; i <= N; i++) sum[i] = sum[i - 1] + v[i];
	for (int i = N; i >= 1; i--) sumb[i] = sumb[i + 1] + v[i];
	maxi[0] = maxidb[0] = 0;
	for (int i = 1; i <= N; i++)
	{
		maxi[i] = max(maxi[i - 1], sum[i] - x[i]);
		maxidb[i] = max(maxidb[i - 1], sum[i] - x[i] * 2);
	}
	ans = maxi[N];
	for (int i = N; i >= 1; i--)
	{
		ans = max(ans, (sum[N] - sum[i - 1] - (C - x[i])) + maxidb[i - 1]);
		ans = max(ans, (sum[N] - sum[i - 1] - (C - x[i]) * 2) + maxi[i - 1]);
	}
	cout << ans << endl;
	return 0;
}