import Control.Applicative main :: IO() main = do [n,k] <- map (read::String->Int) . words <$> getLine print $ case k of 1 -> 0 x | x==n -> 1 | otherwise -> n-1