import Data.Maybe (fromJust)
import qualified Data.ByteString.Char8 as B

solve :: Int -> Int -> Int -> Int -> Int -> Int
solve i j t k s
    | i > s || i > k = t
    | j - i > k || j > s = solve (i + 1) (i + 1) t k s
    | s - j > k = solve i (j + 1) t k s
    | otherwise = solve i (j + 1) (t + 1) k s

main :: IO ()
main = do
    [k, s] <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine :: IO [Int]
    print $ solve 0 0 0 k s
