import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
    [n, m] <- fmap read . words <$> getLine :: IO [Int]
    if m <= n * 2
        then print $ m `div` 2
        else do
            let r = m - n * 2
            print $ n + r `div` 4