module Main where

import Debug.Trace

main :: IO ()
main = do
  [s, c] <- map read . words <$> getLine
  print $ solve s c


solve :: Int -> Int -> Int
solve 0 0 = 0
solve s c = --(s, c) `traceShow`
  if s * 2 > c then c `div` 2 else s + solve ((c - s * 2) `div` 4) ((c - s * 2) `div` 2)
