import Control.Applicative

main = do
  (n:m:_) <- (map read) . words <$> getLine
  print $ f n m

  where
    f :: Int -> Int -> Int
    f n m = a + b
      where
        a = minimum [n, m`div`2]
        b = (m - a*2) `div` 4
