analyzeX n m 
  | (4*n < m) && (2*(n+2) < (m-4))  = analyzeX (n+2) (m-4)
  | (2*n < m) = analyzeX (n+1) (m-2)
  | otherwise = min n (m `div` 2)
  
main = do
  [n, m] <- map (\x -> read x :: Integer) . words <$> getLine 
  print $ analyzeX n m