#include using namespace std; using ll = long long; using pll = pair; #define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i) #define rep(i, n) drep(i, 0, n - 1) #define all(a) (a).begin(), (a).end() #define pb push_back #define fi first #define se second const ll MOD = 1000000007; const ll MOD2 = 998244353; const ll INF = 1LL << 60; const ll N_MAX = 2e5; ll pow_mod(ll x, ll n, ll mod){ ll ret = 1; while(n > 0){ if(n & 1) ret = (ret*x)%mod; x = x*x%mod; n >>=1; } return ret; } vector> mul(vector> A, vector> B, ll mod){ vector> C((ll)A.size(), vector((ll)B[0].size(), 0)); for(ll i=0; i<(ll)A.size(); i++){ for(ll k=0; k<(ll)B.size(); k++){ for(ll j=0; j<(ll)B[0].size(); j++){ C[i][j] = (C[i][j]+A[i][k]*B[k][j])%mod; } } } return C; } vector> mat_pow_mod(vector> A, ll n, ll mod){ ll siz = (ll)A.size(); vector> B(siz, vector(siz, 0)); rep(i, siz) B[i][i] = 1; while(n > 0){ if(n & 1) B = mul(B, A, mod); A = mul(A, A, mod); n >>= 1; } return B; } int main(){ ll n, m; cin >> n >> m; vector> A(2, vector(2, 0)); A[0][0] = 1; A[0][1] = 1; A[1][0] = 1; A = mat_pow_mod(A, n-1, m); cout << A[1][0] << endl; }