let get_2_ints () = Scanf.scanf "%d %d " (fun u v -> u,v)

let () =
  let (s,c) = get_2_ints ()
  in
  (
    let c_left = c-s*2 in
    if c_left >= 0 then (
      s + c_left / 4
    )else(
      let s_true = c / 2
      in s_true
    )
  )
  |> string_of_int |> print_endline