
main = do
  [s,c] <- map read . words <$> getLine
  let 
    count s c n
      | s <= 0 && c <= 0 = n 
      | s <= 0 && c >= 4 = count s (c - 4) (n `seq` n + 1)
      | s >= 1 && c >= 2 = count (s - 1) (c - 2) (n `seq` n + 1)
      | otherwise = n 
  print $ count s c 0
