#include #define rep(i, n) for (int i = 0; i < (n); ++i) #define sz(x) int(x.size()) using namespace std; typedef long long ll; typedef pair P; typedef vector vec; typedef vector mat; const ll INF = 1LL << 60; // const int M = 10000; ll n, M; // A * B mat mul(mat &A, mat &B) { mat C(A.size(), vec(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++) { C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % M; // cout << i << " " << k << " " << j < 0) { if (n & 1) B = mul(B, A); A = mul(A, A); n >>= 1; } return B; } int main() { cin >> n >> M; mat A(2, vec(2)); A[0][0] = 1; A[0][1] = 1; A[1][0] = 1; A[1][1] = 0; // A = mul(A, A); A = pow(A, n - 1); cout << A[1][0] << endl; // rep(i, 2) { // rep(j, 2) { // cout << A[i][j] << " "; // } // cout << endl; // } }