using System;
using System.Collections.Generic;
using System.Linq;
namespace YukiCoder526
{
class Program
{
static void Main(string[] args)
{
var NM = ReadInt();
int N = NM[0];
int M = NM[1];
int[,] A = new int[2, 2];
A[0, 0] = 1; A[0, 1] = 1;
A[1, 0] = 1; A[1, 1] = 0;
A = Pow(A, N - 1, M);
//DrawMapforDebug(A);
Console.WriteLine(A[1, 0]);
Console.ReadKey();
}
///
/// 行列積
///
///
///
///
///
static int[,] Multi(int[,] A, int[,] B, int mod)
{
int[,] R = new int[A.GetLength(0), B.GetLength(1)];
for (int i = 0; i < A.GetLength(0); i++)
{
for (int k = 0; k < B.GetLength(0); k++)
{
for (int j = 0; j < B.GetLength(1); j++)
{
R[i, j] = (R[i, j] + A[i, k] * B[k, j]) % mod;
}
}
}
return R;
}
///
/// 行列累乗
///
///
///
///
///
static int[,] Pow(int[,] A, int n, int mod)
{
int width = A.GetLength(0);
if (width != A.GetLength(1))
{
Console.WriteLine("it is not square matrix.");
}
int[,] B = new int[width, width];
Array.Copy(A, B, A.Length);
int[,] R = new int[width, width];
for (int i = 0; i < width; i++)
{
R[i, i] = 1;
}
while (n > 0)
{
//DrawMapforDebug(B);
if ((n & 1) > 0) R = Multi(R, B, mod);
B = Multi(B, B, mod);
n >>= 1;
}
return R;
}
///
/// 二次元配列の可視化メソッド
///
///
static void DrawMapforDebug(int[,] map)
{
int W = map.GetLength(0);
int H = map.GetLength(1);
int[,] map2 = new int[W + 1, H + 1];
for (int i = 0; i < W + 1; i++)
{
for (int j = 0; j < H + 1; j++)
{
if (i == 0 && j == 0) map2[i, j] = 0;
else if (i == 0) map2[i, j] = j - 1;
else if (j == 0) map2[i, j] = i - 1;
else map2[i, j] = map[i - 1, j - 1];
}
}
for (int i = 0; i < W + 1; i++)
{
for (int j = 0; j < H + 1; j++)
{
Console.Write(map2[i, j] % 10);
}
Console.WriteLine();
}
Console.WriteLine();
}
static int[] ReadInt()
{
int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
return ret;
}
static long[] ReadLong()
{
long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
return ret;
}
}
}