N,C=[int(i) for i in input().split()]
x,v=[[],[]]
for i in range(N): 
	data=input().split()
	x.append(int(data[0]))
	v.append(int(data[1]))
Er=[sum([v[j] for j in range(i+1)])-x[i] for i in range(N)]
El=[sum([v[j] for j in range(i,N)])-C+x[i] for i in range(N)]
Elrback=[El[j]+max([Er[i]-x[i] for i in range(j)]+[0]) for j in range(N)]
Erlback=[Er[j]+max([El[i]-C+x[i] for i in range(j+1,N)]+[0]) for j in range(N)]
print(max(0,max(Elrback),max(Erlback), max(Er), max(El))) 