using System; using System.Linq; using System.IO; using System.Collections.Generic; class Solution { long N, M; long[] memo; long fib(long i) { if (i == 0) return 0; if (i == 1) return 1; if (memo[i] > 0) return memo[i]; return memo[i] = (fib(i - 1) + fib(i - 2)) % M; } public void solve(TextReader input, TextWriter output) { string[] lines = input.ReadLine().Split(' '); N = long.Parse(lines[0]); M = long.Parse(lines[1]); memo = new long[N + 1]; output.WriteLine(fib(N-1)); } } class CaideConstants { public const string InputFile = null; public const string OutputFile = null; } public class Program { public static void Main(string[] args) { Solution solution = new Solution(); using (System.IO.TextReader input = CaideConstants.InputFile == null ? System.Console.In : new System.IO.StreamReader(CaideConstants.InputFile)) using (System.IO.TextWriter output = CaideConstants.OutputFile == null ? System.Console.Out: new System.IO.StreamWriter(CaideConstants.OutputFile)) solution.solve(input, output); } }