#include using namespace std; using ll = long long; using ld = long double; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++) ll x[5000000] = {}; ll fib(ll n,ll m) { if (n == 1) { return 0; } if (n == 2) { return 1; } if (x[n]) { return x[n]; } else { x[n] = fib(n - 1,m)%m + fib(n - 2,m)%m; return x[n]; } } int main() { cin.sync_with_stdio(false); ll N, M; cin >> N >> M; cout << fib(N,M) << endl; return 0; }