
main = do
  [s,c] <- map read . words <$> getLine
  let 
    cs = c `div` 2
    maxS = s + cs
    count s c
      | s <= 0 && c <= 0 = 0
      | s <= 0 && c >= 4 = 1 + count s (c - 4)
      | s >= 1 && c >= 2 = 1 + count (s - 1) (c - 2)
      | s >= 3 && c <= 0 = 1 + count (s - 3) c
      | otherwise = 0
  print $ count s c
