import Data.List apply n f x = foldl' (flip ($)) x (replicate n f) main = do [n,m] <- map read . words <$> getLine print (fibnm n m) fibnm :: Int -> Int -> Int fibnm n m = snd $ apply (n-3) fib (1,1) where fib (x,y) = (y, mod (x+y) m)