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

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