import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;

T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T)(in string str) { return str.split.to!(T[]); }

long mod = pow(10, 9) + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

struct UnionFind
{
	void init(long n) { par = new long[](n); foreach (i; 0..n) par[i] = i; }
	long root(long i) { return par[i] == i ? i : (par[i] = root(par[i])); }
	bool same(long i, long j) { return root(i) == root(j); }
	void unite(long i, long j) { i = root(i); j = root(j); if (i == j) return; par[i] = j; }
	long[] par;
}

void main()
{
	auto N = RD!long;
	auto C = RD!long;

	auto x = new long[](N);
	auto v = new long[](N);
	foreach (i; 0..N)
	{
		x[i] = RD!long;
		v[i] = RD!long;
	}

	auto dp = new long[2][2][](N+1);
	foreach (i; 0..N)
	{
		dp[i+1][0][0] = dp[i][0][0] + v[i];
		dp[i+1][0][1] = max(dp[i][0][1], dp[i+1][0][0] - x[i] * 2);
	}
	foreach_reverse (i; 0..N)
	{
		dp[i][1][0] = dp[i+1][1][0] + v[i];
		dp[i][1][1] = max(dp[i+1][1][1], dp[i][1][0] - (C - x[i]) * 2);
	}

	long ans;
	foreach (i; 0..N)
	{
		auto cal1 = dp[i+1][0][0] - x[i];
		auto cal2 = dp[i+1][1][1];
		ans = max(ans, cal1 + cal2);
	}
	foreach_reverse (i; 0..N)
	{
		auto cal1 = dp[i][1][0] - (C - x[i]);
		auto cal2 = dp[i][0][1];
		ans = max(ans, cal1 + cal2);
	}

	writeln(ans);
	stdout.flush();
}