main = (readLn :: IO Int) >>= print . flip mod 123456