import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.Maybe (fromJust)
import Debug.Trace

solve :: Integer -> Integer -> Integer
solve n m
    | n * 2 >= m = (m `div` 2)
    | otherwise = n + fromC
    where
        fromC = (m - n * 2) `div` 4

main :: IO ()
main = do
    (n:m:_) <- map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine
    print $ solve n m