import sys
input = sys.stdin.readline

def main():
	N,C = map(int,input().split())
	X = [list(map(int,input().split())) for  _ in range(N)]
	stand_c = 0
	stand_cc = C
	clock = [0 for _ in range(N+1)]
	c_clock = [0 for _ in range(N+1)]

	for i in range(N):
		clock[i+1] = clock[i]+X[i][1]-(X[i][0]-stand_c)
		stand_c = X[i][0]
		c_clock[i+1] = c_clock[i]+X[-i-1][1]-(stand_cc-X[-i-1][0])
		stand_cc = X[-i-1][0]

	ans = 0
	for i in range(N+1):
		if i == 0:
			ans = max(ans,max(c_clock))
		elif i == N:
			ans = max(ans,max(clock))
		else:
			cal = clock[i]-X[i-1][0]+max(c_clock[:(N-i+1)])
			c_cal = c_clock[i]-(C-X[-i][0])+max(clock[:(N-i+1)])
			ans = max(ans,cal,c_cal)

	print(ans)

if __name__ == "__main__":
	main()