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	a>b  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