// clang-format off #include using namespace std; #if __has_include() #include using namespace atcoder; #endif #define _overload3(_1,_2,_3,name,...) name #define _REP(i,n) REPI(i,0,n) #define REPI(i,a,b) for(int i=int(a);i=int(b);--i) #define RREP(...) _overload3(__VA_ARGS__,RREPI,_RREP,)(__VA_ARGS__) #define ALL(a) (a).begin(),(a).end() #define ALLR(a) (a).rbegin(),(a).rend() typedef long long ll; const int INF32 = 1001001001; const long long INF64 = 1001001001001001001; struct Init { Init() { ios::sync_with_stdio(0); cin.tie(0); cout << setprecision(15); }} init; template bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template T gcd(T x, T y){ return (x % y) ? gcd(y, x % y) : y; } template T lcm(T x, T y){ return x / gcd(x, y) * y; } template void output(const T& a, const Ts&... b) { cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; } template void output(vector v) { for (auto u : v) cout << u << ' '; cout << '\n'; }; void yesno(bool is_ok) { cout << (is_ok ? "yes" : "no") << '\n'; } void YesNo(bool is_ok) { cout << (is_ok ? "Yes" : "No") << '\n'; } void YESNO(bool is_ok) { cout << (is_ok ? "YES" : "NO") << '\n'; } // clang-format on template vector> matrix_mul(const vector> &a, const vector> &b) { vector> 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]; } } } return res; } template vector> matrix_pow(vector> a, long long n) { vector 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 = matrix_mul(a, res); a = matrix_mul(a, a); n >>= 1; } return res; } using mint = modint; int main() { int n; ll m; cin >> n >> m; mint::set_mod(m); auto po = matrix_pow({{1, 1}, {1, 0}}, n - 1); auto mu = matrix_mul(po, {{1}, {0}}); output(mu[1][0].val()); }