import numpy as np def calFibonatti(N,M): if N<=3: if N == 1: return 0 return 1 N = N - 3 A = np.zeros((2,2), dtype='int32') A[0][0]=1 A[0][1]=1 A[1][0]=1 A[1][1]=0 result = np.copy(A) for i in range(N): result = np.mod(result.dot(A),M) return result[0][0] N,M = map(int, input().split()) print(calFibonatti(N, M))