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 rec sc s c x =
if s <= c then sc (s/2 + (s mod 2)) (c-s+ (s mod 2)) (x+s/2) 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