getNumber :: String -> (Integer, Integer)
getNumber xs = (read $ fst h, read $ tail $ snd h)
  where h = break (== ' ') xs

reduceNums :: (Integer, Integer) -> Integer 
reduceNums (0,y) = y `div` 4
reduceNums (x,y) = if y `div` x >= 1 
                     then x + (y - 2 * x) `div` 4
                     else y `div` 2
main = do
  nums <- fmap (reduceNums.getNumber) getLine
  putStrLn $ show nums
