#include <iostream>
#include <vector>
using namespace std;

#include <iostream>
#include <cassert>

template<long long mod>
class modint{
private:
  using T = long long;
  T a;
public:
  constexpr modint(const long long x = 0) noexcept : a((x%mod+mod)%mod) {}
  constexpr T& value() noexcept { return a; }
  constexpr const T& value() const noexcept { return a; }
  constexpr modint operator-() const noexcept {
    return modint(0) -= *this;
  }
  constexpr modint operator+(const modint& rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint& rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint& rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint& rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint& operator+=(const modint& rhs) noexcept {
    a += rhs.a;
    if(a >= mod) a -= mod;
    return *this;
  }
  constexpr modint &operator-=(const modint& rhs) noexcept {
    if(a < rhs.a) a += mod;
    a -= rhs.a;
    return *this;
  }
  constexpr modint& operator*=(const modint& rhs) noexcept {
    a = a*rhs.a%mod;
    return *this;
  }
  constexpr modint& operator/=(const modint& rhs) noexcept {
    return *this *= rhs.inv();
  }
  constexpr bool operator==(const modint& rhs) const noexcept {
    return a == rhs.a;
  }
  constexpr bool operator!=(const modint& rhs) const noexcept {
    return not (*this == rhs);
  }
  constexpr modint pow(long long k) const noexcept {
    modint ret(1);
    modint x = k > 0 ? *this : this->inv();
    k = abs(k);
    while(k > 0){
      if(k&1) ret *= x;
      x *= x;
      k >>= 1;
    }
    return ret;
  }
  constexpr modint inv() const noexcept {
    return pow(mod-2);
  }
  friend std::ostream& operator<<(std::ostream &os, const modint &X) noexcept {
    return os << X.a;
  }
  friend std::istream& operator>>(std::istream &is, modint &X) noexcept {
    is >> X.a;
    X.a %= mod;
    if(X.a < 0) X.a += mod;
    return is;
  }
};

template<typename T>
T power(T x, long long k){
  T ret{1};
  while(k > 0){
    if(k&1) ret *= x;
    x *= x;
    k /= 2;
  }
  return ret;
}

int main(){
  using mint = modint<998244353>;
  int n, m;
  cin >> n >> m;
  mint ans = 0;
  vector<mint> pow_m(n+1);
  pow_m[0] = 1;
  for(int i = 0; i < n; ++i)
    pow_m[i+1] = pow_m[i]*m;
  for(int i = 1; i <= m; ++i){
    ans += power<mint>(m-i+1,n) - power<mint>(m-i,n);
    mint a = 1, b = 1;
    for(int j = 1; j+1 <= n; ++j){
      a *= m-i+1, b *= m-i;
      if(j+2 <= n){
        mint p = a - b;// i が 1 回以上使われる
        p *= n-j-1;// 長さ j+2 の区間の取り方
        p *= (i-1)*(i-1);//両端
        p *= pow_m[n-j-2];//残り
        ans += p;
      }
      mint q = a - b;
      q *= 2;
      q *= i-1;//両端
      q *= pow_m[n-j-1];//残り
      ans += q;
    }
  }
  cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define int ll
#define ll long long
#define db double
#define rep(i,be,en) for(int i=be;i<=en;i++)
const int INF = 0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
//const double pi=acos(-1);
const int mod=1e9+7;
#define eps 1e-8
#define zero(x) (((x)>0?(x):-(x))<eps)
using namespace std;
const int N=1e5+7;
const int M=1e6+7;

inline int read(){
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}

int T,n,m,fl;


signed main(){
	n=read();
	int x=1,a=0,b=0,c=0,ans,aa,bb,cc;
	a=n/x;
	ans=a;aa=a;bb=0;cc=0;
	while(x*2<=n){
		b++;
		x*=2;
		a=n/x;
		c=n%x;
		if(a+b+c<ans){
			ans=a+b+c;
			aa=a;bb=b;cc=c;
		}
	}
	
	printf("%lld\n",ans,aa,bb,cc);
	
}
