import Control.Applicative ((<$>), (<*>))
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = do
  solve <$> getl (readi B.readInt) <*> getl (readi B.readInt) <*> getl (readi B.readInt) >>= print

solve :: Int -> Int -> Int -> Int
solve x a b = (x - a) `mod` b

fibs :: [Int]
fibs = 1:1:zipWith (+) (tail fibs) fibs

getl :: (ByteString -> a) -> IO a
getl f = f <$> B.getLine

readi :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> a
readi f s = let Just (n, _) = f s in n
