import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [s,c] <- getIntList
    let ans | c `div` 2 <= s = c `div` 2
            | otherwise = s + ((c-s*2) `div` 4)
    print ans