N, C = map(int, raw_input().split())
a = []
d = []
A = []
AA = []
for i in range(N):
	x, v = map(int, raw_input().split())
	a.append(x, C-x, v)
	d.append([])
d[0] = a[0][2] - a[0][0]
d[N-1] = a[N-1][2] - a[N-1][1]
A.append(0)
A.append(N-1)
AA.append(d[0])
AA.append(d[N-1])
while True:
	c = A[AA.index(max(AA))]
	if c == 0:
		nx = 1
		pv = N - 1
	elif c == N-1:
		nx = 0
		pv = N - 2
	else:
		nx = c + 1
		pv = c - 1
	if d[nx] == []:
		d[nx] = d[c] + a[nx][2] - a[nx][0]
		A.append(nx)
		AA.append(d[nx])
	elif d[nx] < d[c] + a[nx][2] - a[nx][0]:
		d[nx] = d[c] + a[nx][2] - a[nx][0]
	if d[pv] == []:
		d[pv] = d[c] + a[pv][2] - a[pv][1]
		A.append(pv)
		AA.append(d[pv])
	elif d[pv] < d[pv] + a[pv][2] - a[pv][1]:
		d[pv] = d[c] + a[pv][2] - a[pv][1]
	A.pop(c)
	AA.pop(c)
	if nx == pv:
		print max(d)
