-- yukicoder My Practice -- author: Leonardone @ NEETSDKASU main = print . solve . map read . words =<< getLine solve [n,k] | k < 1 || n < k || n < 2 = 0 | odd n && n + 1 == k * 2 = n - 1 | otherwise = n - 2