module Main where import Control.Monad _max = 2000000000 main :: IO () main = do [a, b] <- fmap read . words <$> getLine :: IO [Int] case a `compare` b of LT -> print $ b - 2 GT -> print $ (_max - a) + (a - b - 1)