let id x = x
let (n,m) = Scanf.scanf "%d %d\n" (fun n m -> (n,m))
 
let sc s c x =
if (2*s) <= c then ((c-2*s),s) else (0,c/2)
 
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