solve :: [Int] -> Int solve [n, m] = solveGo 0 1 n where solveGo f1 _ 1 = f1 solveGo f1 f2 x = solveGo f2 (mod (f1 + f2) m) (x - 1) solve _ = error "" main :: IO () main = getLine >>= print . solve . map read . words