#include using namespace std; #define rep(i, n) for (decltype(n) i = 0; i < (n); ++i) #define rep3(i, s, n) for (decltype(n) i = (s); i < (n); ++i) #define repR(i, n) for (decltype(n) i = (n)-1; i >= 0; --i) #define rep3R(i, s, n) for (decltype(n) i = (n)-1; i >= (s); --i) #define repit(it, c) for (auto it = (c).begin(); it != (c).end(); ++it) #define all(x) ::std::begin(x), ::std::end(x) template inline bool chmax(T ¤t, const U &test) { if (current < test) { current = test; return true; } return false; } template inline bool chmin(T ¤t, const U &test) { if (current > test) { current = test; return true; } return false; } using ll = long long; const int64_t INFL = pow(10, 18); const int INF = 2 * pow(10, 9); struct matrix { ll a, b, c, d; matrix() {} matrix(ll a, ll b, ll c, ll d) : a(a), b(b), c(c), d(d) {} }; matrix prod(matrix &m1, matrix &m2, ll mod) { matrix p; p.a = (m1.a * m2.a + m1.b * m2.c) % mod; p.b = (m1.a * m2.b + m1.b * m2.d) % mod; p.c = (m1.c * m2.a + m1.d * m2.c) % mod; p.d = (m1.c * m2.b + m1.d * m2.d) % mod; return p; } matrix power(matrix m, ll p, ll mod) { matrix ret(1, 0, 0, 1); while (p > 0) { if (p & 1) { ret = prod(ret, m, mod); } m = prod(m, m, mod); p >>= 1; } return ret; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); constexpr char endl = '\n'; /////////////////////////// ll n, m; cin >> n >> m; matrix mat = power(matrix(1, 1, 1, 0), n - 2, m); ll ans = mat.a * 1; cout << ans << endl; }