import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readLine >>= print . solve 

-- |
-- >>> solve [1,6]
-- 2
-- >>> solve [12345,678901]
-- 175897
solve :: [Int] -> Int 
solve [n, m] 
    | m < 2 * n = m `div` 2
    | otherwise = n + (m - 2 * n) `div` 4


readLine :: IO [Int]
readLine = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine