Module Module1
    Sub Main()
    Dim a as integer
  	Dim b as integer
  	Dim c as integer
    Dim d as integer
    Dim f as integer
 
 
  	Dim ans as integer
    Dim input() as string = Console.ReadLine().split(" ")
    
     	a=integer.parse(input(2))
     	b=integer.parse(input(1))
     	c=integer.parse(input(3))
    	d=integer.parse(input(0))
    	
    if a>d Then
      f=a
    Else 
      f=d
    End if 
     	if input(2)>input(1) Then
			ans=0
      　Elseif b>c Then 
      ans= c-f
    	Elseif b<c Then
      ans= b-f
    	End if
    
      	Console.WriteLine(ans)
    End Sub
End Module