import qualified Data.Vector as V main :: IO () main = do [n, m] <- map read . words <$> getLine print $ solve n m solve :: Int -> Int -> Int solve n m = dp V.! (n - 1) where dp = V.map f $ V.fromList [0 .. n - 1] f 0 = 0 f 1 = 1 f i = mod (dp V.! (i - 1) + dp V.! (i - 2)) m