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

let () =
  let (n,m) = get_2_ints ()
  in 
  let scc,c_left = n,m-n*2
  in let s_new = c_left / 4
  in
  let scc = scc + s_new
  in 
  scc |> string_of_int |> print_endline