program main
	implicit none
	integer a,b,c,d,x
	read(*,*)a,b,c,d
	if((a<c.and.b>d).or.(a>c.and.b<d))then
		x=min(b-a,d-c)
	else
		if(a<c)then
			x=b-c
		else
			x=d-a
		endif
	endif
	if(x<0)x=0
        write(*,*)x
end program main
