import numpy as np n,m=map(int,input().split()) mod=m def seq_mat(A,k,mod): if k==1: return A else: if k%2==0: tmp=seq_mat(A,k//2,mod) ret=np.dot(tmp,tmp) else: tmp=seq_mat(A,k-1,mod) ret=np.dot(A,tmp) for i in range(2): for j in range(2): ret[i][j]%=mod return ret A=np.array([[1,1],[1,0]]) if n<=2: print((n-1)%mod) else: fib_n=seq_mat(A,n-2,mod)[0][0] print(fib_n)