a=int64(scanf("%ld"));
n=a(1);
c=a(2);
x=a(3:2:end);
v=a(4:2:end);
fa=cummax([0;cumsum(v)-x]);
fb=cummax([0;cumsum(v(end:-1:1))-c+x(end:-1:1)]);
%disp(max([fa(end);fb(end);fa(1:end-1)+fb(end-1:-1:1)-min(x(1:end-1),x(end-1:-1:1))]))
disp(max(fa+flip(fb)-min(X=[0;x],flip(X))))
%disp([flip(fa)+cumsum(flip(v))-c*2+flip(x)*2;flip(fb)+cumsum(v)-x*2])