import Data.Int import Data.Array main = do [n,m] <- map read . words <$> getLine :: IO [Int64] let fib = array (1,n) $ (1,0) : (2,1) : [(i,(fib!(i-1)+fib!(i-2))`mod`m) | i<-[3..n]] :: Array Int64 Int64 print $ fib!n