#include using namespace std; map fib; long long fibonacci(long long N,long long mod){ if(fib[N]!=0) return fib[N]; if(N==0) return fib[N] = 0; if(N==1 || N==2) return fib[N] = 1; if(N%2==0){ return fib[N] = (((fibonacci(N/2+1,mod) * fibonacci(N/2,mod)) % mod) + (fibonacci(N/2,mod) * fibonacci(N/2-1,mod)) % mod) % mod; }else if(N%2==1){ return fib[N] = (((fibonacci((N+1)/2,mod) * fibonacci((N+1)/2,mod)) % mod) + (fibonacci((N-1)/2,mod) * fibonacci((N-1)/2,mod)) % mod) % mod; } return -1; } int main(){ long long N,M; cin >> N >> M; cout << fibonacci(N-1,M) << endl; }