solve :: [Int] -> Int solve [n, m] = head . drop (n - 1) $ fib where fib = [0, 1] ++ [(`mod` m) . sum . take 2 . drop x $ fib | x <- [0 .. ]] solve _ = error "" main :: IO () main = getLine >>= print . solve . map read . words