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