#include "bits/stdc++.h" using namespace std; using lint = long long; typedef vector > mat; lint MOD = 17; mat mul(mat &a, mat&b){ mat c(a.size(), vector (b[0].size())); for(int i = 0; i < a.size(); i++){ for(int k = 0; k < b.size(); k++){ for(int j = 0; j < b[0].size(); j++){ if(MOD != 0)c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % MOD; } } } return c; } mat pow_matrix(mat &a, lint N){ mat b(a.size(), vector (a.size())); for(int i = 0; i < a.size(); i++) b[i][i] = 1; while(N > 0){ if(N & 1) b = mul(b, a); a = mul(a, a); N >>= 1; } return b; } signed main(){ lint N, MOD; cin >> N >> MOD; mat a(2, vector (2)); a[0][0] = 1; a[0][1] = 1; a[1][0] = 1; a[1][1] = 0; a = pow_matrix(a, N - 1); cout << a[1][0] << endl; }