// 2380

#include <bits/stdc++.h>
using namespace std;

namespace mod_pow {
template <typename T, typename U>
T pow(T x, unsigned long t, U m) {
  if (!t) {
    return 1;
  }
  T y = pow(x, t >> 1, m);
  y = y * y % m;
  if (t & 1) {
    y = y * x % m;
  }
  return y;
}
}

template <typename T, typename U>
T legendre(T n, U p) {
  T e = 0;
  T d = p;
  while (d <= n) {
    e += n / d;
    d *= p;
  }
  assert(e < n);
  return e;
}

auto main() -> int {
  long n, p;
  cin >> n >> p;
  // n!がp^eで割り切れるような最大のp^e
  constexpr int mod = 998'244'353;
  long e = legendre(n, p);
  cout << mod_pow::pow(p, e, mod) << '\n';
}