fib :: Integer -> Integer fib n = fib' n 1 1 where fib' n x y | n == 1 = 1 | n == 2 = 1 | n == 3 = x | otherwise = n' `seq` x' `seq` fib' n' x' x where n' = (n - 1) x' = (x + y) main = do x <- getLine print $ mod (fib $ read $ head (words x)) (read (words x !! 1))