//#define _GLIBCXX_DEBUG #include //#include using namespace std; //using namespace atcoder; using ll = long long; #define rep(i, s, n) for (ll i = (s); i < (ll)(n); i++) #define all(x) (x).begin(), (x).end() #define in(x, l, r) (ll)(l) <= (x) && (x) < (ll)(r) int m, MOD; vector matmul(vector &dp, vector> &mt) { vector ret(m,0); rep(i,0,m) rep(j,0,m) ret[i] = (ret[i] + mt[i][j] * dp[j]) % MOD; return ret; } vector> update(vector> &mt) { vector> ret(m, vector(m,0)); rep(i,0,m) rep(j,0,m) rep(k,0,m) ret[i][j] = (ret[i][j] + mt[i][k] * mt[k][j]) % MOD; return ret; } void matpow(vector &dp, vector> &mt, int k) { m = dp.size(); while (k) { if (k&1) dp = matmul(dp,mt); mt = update(mt); k /= 2; } } int main() { int N; cin >> N >> MOD; vector dp = {1, 0}; vector> mt = {{1,1}, {1,0}}; matpow(dp,mt,N-2); cout << dp[0] << endl; }