#include using namespace std; typedef long long ll; const int MAXN = 2e5 + 5; const int MOD = 998244353; ll fac[MAXN], inv[MAXN]; ll qpow(ll a, ll b, ll mod) { ll res = 1; while(b) { if(b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } void init(int p) { fac[0] = 1; for(int i = 1; i <= p; ++i) fac[i] = fac[i - 1] * i % p; inv[p - 1] = qpow(fac[p - 1], p - 2, p); for(int i = p - 2; i >= 0; --i) inv[i] = inv[i + 1] * (i + 1) % p; } ll C(ll n, ll m, ll p) { if(m > n || m < 0) return 0; return fac[n] * inv[m] % p * inv[n - m] % p; } ll Lucas(ll n, ll m, ll p) { if(!m) return 1; return C(n % p, m % p, p) * Lucas(n / p, m / p, p) % p; } int main() { ll n, p; scanf("%lld%lld", &n, &p); init(p); ll ans = 0; for(ll i = 0; i <= n; ++i) { ans = (ans + Lucas(n, i, p)) % MOD; } printf("%lld\n", ans); return 0; }