solver::Int->Int->Int
solver n m = let first_proc = min n (div m 2)    in
             let rest_c     = m-(first_proc * 2) in
             if rest_c <= 1 then first_proc else first_proc + (div rest_c 4)

main::IO()
main =do
  dc<-getLine
  let n:m:[]= map read (words dc)::[Int]
  print (solver n m)
