let () = Printf.printf "%d\n" ans

let id x = x
let (n,m) = Scanf.scanf "%d %d\n" (fun n m -> (n,m))

let rec sc1 s c x =
if s > 0 && c > 1 then sc1 (s-1) (c-2) (x+1) else (c,x)

let sc s c x =
if (2*s) <= c then ((c-2*s),s) else sc1 s c x

let cx = sc n m 0
let c = fst cx
let x = snd cx

let ans = x + c/4

let () = Printf.printf "%d\n" ans