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

solve :: Int -> Int -> Int
solve n m 
  | val >= 0 = n + val `div` 4
  | otherwise = m `div` 2
  where
    val = m-2*n
