using System; using System.Linq; using System.Collections.Generic; public class yukicoder { private static Dictionary Memo; public static long fib(int n) { Memo = new Dictionary(); return _fib(n); } private static long _fib(int n) { if (n == 0) return 0; if (n == 1) return 1; if (!Memo.ContainsKey(n)) { Memo[n] = _fib(n - 2) + _fib(n - 1); } return Memo[n]; } public static void Main() { int[] foo = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int a = foo[0]; int b = foo[1]; Console.WriteLine(fib(a - 1) % b); } }