import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as C

-- solve m n acc
--   | m /= 0 && n >= 2 = solve (m - 1) (n - 2) (acc + 1)
--   | n >= 4 = solve m (n - 4) (acc + 1)
--   | otherwise = acc

solve m n =
  let (nn, acc1) = (n - (m * 2), m)
  in acc1 + (div nn 4)

main = do
  [m, n] <- readInts
  -- print $ solve 1 6
  -- print $ solve 12345 678901
  print $ solve m n
  where
    toInt :: String -> Int
    toInt = read

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

readNInts :: Int -> IO [[Int]]
readNInts = flip replicateM readInts

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . C.readInteger) . C.words <$> C.getLine

readNIntegers :: Int -> IO [[Integer]]
readNIntegers = flip replicateM readIntegers
