let solve n_S n_c =
  if n_S = (n_c/2) then
    n_S
  else if n_S > (n_c/2) then
    n_c/2
  else (* n_S < (n_c/2) *)
    let resid = n_c - 2 * n_S in
    resid/4 + n_S

let () =
  let rec read () =
    try let ans = (Scanf.scanf "%d %d\n" solve) in
        Printf.printf "%d\n" ans
    with End_of_file -> ()
  in
  read ()
;;
