N,C = map(int,input().split())
x,v = [],[]
for i in range(N):
	X,V = map(int,input().split())
	x.append(X)
	v.append(V)

V_tokei = []
V_hantokei = []
for i in range(N):
	if i == 0:
		V_tokei.append((v[i] - x[i], x[i]))
		V_hantokei.append(((v[N-i-1] - (C - x[N-i-1])), x[N-i-1]))
	else:
		V_tokei.append(((V_tokei[i-1][0] + v[i] - (x[i] - V_tokei[i-1][1])), x[i]))
		V_hantokei.append(((V_hantokei[i-1][0] + v[N-i-1] - (V_hantokei[i-1][1] - x[N-i-1]), x[N-i-1])))

# n <= i での V_hantokeiの最大値
V_hantokei_max = [V_hantokei[0][0]]
# n <= i での V_tokeiの最大値
V_tokei_max = [V_tokei[0][0]]
for i in range(1,N):
	V_hantokei_max.append(max(V_hantokei_max[i-1], V_hantokei[i][0]))
	V_tokei_max.append(max(V_tokei_max[i-1], V_tokei[i][0]))

v_mix_max = 0
for i in range(0, N-1):
	v_mix_max = max(v_mix_max, V_tokei[i][0] - V_tokei[i][1] + V_hantokei_max[N - i - 2])
	v_mix_max = max(v_mix_max, V_hantokei[i][0] - (C - V_hantokei[i][1]) + V_tokei_max[N - i - 2])
print(max(max([v[0] for v in V_hantokei] + [0]), max([v[0] for v in V_tokei] + [0]), v_mix_max))

