main = do [n, k] <- map read . words <$> getLine print $ solve n k solve :: Int -> Int -> Int solve n k = if k == 0 || k > n then 0 else if n + 1 == 2 * k then n - 1 else n - 2