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