#include using namespace std; // #include // using namespace atcoder; using ll = long long; using ull = unsigned long long; using ldb = long double; using P = pair; #define fi first #define se second #define m_99(i,a,b) for (ll i = a, i##_range = (b); i < i##_range; i++) #define REP(i,a,b) m_99(i,a,b) #define rep(i,a) m_99(i,0,a) template bool chmin(T& a, const T& b) { return a > b ? a = b, true : false; } template bool chmax(T& a, const T& b) { return a < b ? a = b, true : false; } #ifdef _DEBUG #include #define debug(...) debug::dprint(#__VA_ARGS__, __VA_ARGS__) #else #define debug(...) (static_cast(0)) #endif struct initialise { initialise() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }__INI__; const ll inf = 1LL << 60; const ll dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1}; /*---------------------------------------------------------------------------------------------------       ○______       ||      |       ||  ●   |       ||      |     || ̄ ̄ ̄ ̄ ̄      || 君が代は ∧__,,∧||  千代に八千代に   ( `・ω・|| さざれ石の巌となりて   ヽ つ0 こけのむすまで    し―-J ---------------------------------------------------------------------------------------------------*/ using mat = vector>; ll MOD; /// 行列積 mat mat_mul(mat &a, mat &b) { mat res(a.size(), vector(b[0].size())); for (int i = 0; i < a.size(); i++) { for (int j = 0; j < b[0].size(); j++) { for (int k = 0; k < b.size(); k++) { (res[i][j] += a[i][k] * b[k][j]) %= MOD; } } } return res; } /// 行列累乗 mat mat_pow(mat a, long long n) { mat res(a.size(), vector(a.size())); // 単位行列で初期化 for (int i = 0; i < a.size(); i++) res[i][i] = 1; // 繰り返し二乗法 while (n > 0) { if (n & 1) res = mat_mul(a, res); a = mat_mul(a, a); n >>= 1; } return res; } int main(void){ ll n; cin >> n >> MOD; n--; vector> a = {{0, 1}, {1, 1}}; a = mat_pow(a, n); cout << a[0][1] << '\n'; }