let memoize f = let memo = System.Collections.Generic.Dictionary<_,_>() (fun x -> match memo.TryGetValue x with | true, v -> v | _ -> let v = f(x) in memo.Add(x,v); v) let rec fib = let modulo = Microsoft.FSharp.Core.int.MaxValue |> int64 let f = function | 0 -> 0L | 1 -> 1L | x -> (fib (x - 1) + fib (x - 2)) % modulo f |> memoize let f n m = let longM = m |> int64 let zeroIndexedN = n - 1 let a = fib zeroIndexedN a % longM let N,M = let t = stdin.ReadLine().Split() |> Array.map int t.[0], t.[1] f N M |> printfn "%i"