N, C = map(int, raw_input().split())
a = []
b = []
c = []
for i in range(N):
	a.append(map(int, raw_input().split()))
b.append(a[0][1] - a[0][0])
for i in range(1, N):
	b.append(b[i-1] + a[i][1] - a[i][0])
c.append(a[N][1] + a[N][0] - C)
for i in range(1, N):
	c.append(c[i-1] + a[N-i][1] + a[N-i][0] - C)
if max(b) < max(c):
	print max(c)
else:
	print max(b)