let main () = Scanf.sscanf (read_line ()) "%d %d %d %d"
  (fun a b c d -> print_int(if b < c || d < a then 0
    else if b = d && a < c then d-c 
    else if b = d && a > c then d-a
    else if a = c && b < d then b-a
    else if a = c && b > d then d-a
    else if a < c && b > d then d-c
    else if a > c && d > b then b-a
    else if a < c && b < d then (((b-a)+(d-c)) -(d-a)) else (((b-a)+(d-c)) -(b-c))))
let _ = main()