import Control.Applicative main = do input <- fmap(read :: String -> Int) <$> words <$> getLine print $ f input f (a:b:s:_) | s == 1 = abs (a - s) + s | otherwise = if abs (a - s) <= abs (b - s) then abs (a - s) + s else abs (b - s) + s - 1 + a