import Data.List (foldl') solve :: [Int] -> Int solve [n, m] = fst $ foldl' solveGo (0, 1) [2 .. n] where solveGo (f1, f2) _ = (f2, mod (f1 + f2) m) solve _ = error "" main :: IO () main = getLine >>= print . solve . map read . words