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 a < c && b > d then d-c
    else if a > c && d > b then b-a
    else ((b-a)+(d-c)) -(d-a)))
let _ = main()