import Data.List

toInt :: String -> Int
toInt = read :: String -> Int

solve :: (Int, Int) -> Int
solve (n, m)
  | 2*n >= m = n
  | otherwise = n + div (m-2*n) 4

main = do
  [n, m] <- map toInt . words <$> getLine
  print $ solve (n, m)
