{-# LANGUAGE BangPatterns #-}
import Data.List
import Data.Maybe
import Data.Function (fix)
import Data.Array (Array, array, (!))
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8

modular :: Integer
modular = 1000000007
 
getInts :: IO [Int]
getInts = (map parseInt . BS8.words) <$> BS.getLine 
    where parseInt = fst . fromJust . BS8.readInt

getIntegers :: IO [Integer]
getIntegers = (map parseInteger . BS8.words) <$> BS.getLine 
    where parseInteger = fst . fromJust . BS8.readInteger

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

main :: IO ()
main = do
    [n, m] <- getIntegers
    print $ solve n m