a=scanf("%d");
n=a(1);
c=a(2);
x=a(3:2:end);
v=a(4:2:end);
fa=cummax(cumsum(v)-x);
fb=cummax(cumsum(v(end:-1:1))-c+x(end:-1:1));
disp(min(fa(end),fb(end),fa(1:end-1)+fb(end-1:-1:1)+min(x(1:end-1),x(end-1:-1:1))))