main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  print $ solve n m

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