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-1):
	b.append(b[i-1] + a[i][1] - a[i][0])
c.append(a[N-1][1] + a[N-1][0] - C)
for i in range(1, N-1):
	c.append(c[i-1] + a[N-i-1][1] + a[N-i-1][0] - C)
if max(b) < max(c):
	if max(c) > 0:
		print max(c)
	else:
		print 0
else:
	if max(b) > 0:
		print max(b)
	else:
		print 0