using System; using System.IO; using System.Text; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Numerics; using System.Linq.Expressions; using System.Linq; using System.Diagnostics; public class Csharp_Work { static long m; static long[, ] Mul(long[, ] a, long[, ] b) { var res = new long[a.GetLength(0), b.GetLength(1)]; for(int i = 0; i < a.GetLength(0); ++i) { for(int j = 0; j < b.GetLength(1); ++j) { for(int k = 0; k < a.GetLength(1); ++k) { res[i, j] += a[i, k] * b[k, j]; res[i, j] %= m; } } } return res; } // 正方行列の累乗 static long[, ] Pow(long[, ] a, long n) { long lng = a.GetLength(0); var res = new long[lng, lng]; var a_tmp = a.Clone() as long[, ]; // 単位行列 for(int i = 0; i < lng; ++i) { res[i, i] = 1; } long num = n; while(num > 0) { if((num & 1) != 0) { res = Mul(res, a_tmp); num -= 1; continue; } a_tmp = Mul(a_tmp, a_tmp); num >>= 1; } return res; } static void Main(string[] args) { var fibo = new long[2, 2]; fibo[0, 0] = 1; fibo[0, 1] = 1; fibo[1, 0] = 1; fibo[1, 1] = 0; var tmp = Console.ReadLine().Split(); long n = long.Parse(tmp[0]); m = long.Parse(tmp[1]); var res = Pow(fibo, n - 2); Console.WriteLine(res[0, 0]); } }