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

reduceNums :: (Integer, Integer) -> Integer 
reduceNums (x,y)
  | y == 1 || y == 0    = 0
  | x <= 0              = reduceNums (x + 1,y - 2)
  | otherwise           = 1 + reduceNums (x - 1,y - 2)

main = do
  nums <- fmap (reduceNums.getNumber) getLine
  putStrLn $ show nums