import Data.List (unfoldr) solve :: [Int] -> Int solve [n, m] = (!! (n - 1)) $ unfoldr fib (0, 1) where fib (f1, f2) = Just (f1, (f2, mod (f1 + f2) m)) solve _ = error "" main :: IO () main = getLine >>= print . solve . map read . words