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

  
main = do
  [m, n] <- readInts
  -- print $ solve 1 6 0
  -- print $ solve 12345 678901 0
  print $ solve m n 0
  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
