#include <bits/stdc++.h>
using namespace std ;
#define time cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl "\n"
typedef unsigned long long int ull ;
#define int long long   
int MOD = 1e7+7 ;


int gcd(int a, int b){
  if(b==0)
    return a ;  
  return gcd ( b , a % b) ; 
}

int lcm (int a ,int b ){
  return (a*b)/gcd(a,b) ; 
}
 
void solve(){
   
  int  a; int b ; 
  cin >> a >> b  ; 

  int c = a+b  ;  

  if(c>=15 && b>=8){
    cout << 1 ; 
  }
  else
  if(c>=10 && b>=3){
    cout << 2; 
  }
  else
  if(c>=3){
    cout << 3;  
  }
  else{
    cout << 4 ; 
  }


}
int32_t main()
{
  fast ;   time ;
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif
  
  
  solve()  ;  
  return 0; 
}
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using LL = long long;
using LD = long double;
using ordered_set = tree<LL,null_type,less<LL>,rb_tree_tag,tree_order_statistics_node_update>;

void fastio() {
	cin.tie(nullptr);
	cin.sync_with_stdio(false);
}

const LL MOD = 998244353;
const LL INF = 1e18;
const LL N = 2e5+5;

#define S second
#define F first
#define vt vector

LL binpow(LL x, LL p, LL m) {
	LL res = 1;
	x %= m;
	while (p) {
		if (p&1) {
			res = res * x % m;
		}
		x = x * x % m;
		p >>= 1;
	}
	return res;
}

int main() {
	fastio();

	LL n, m;
	cin >> n >> m;

	LL sub = 0;

	LL mi = binpow(m, MOD-2, MOD);
	LL mp = binpow(m, n-1, MOD);

	vt<LL> dmx(m+1, 1);

	for (LL d = 2; d <= n; ++d) {
		LL tim = n-d+1;
		LL res = 0;

		mp = (mp*mi) % MOD;
		
		for (LL x = 1; x <= m; ++x) {
			//
			res = (res + dmx[m-x] % MOD * mp) % MOD;
			dmx[m-x] = dmx[m-x]*(m-x) % MOD;
		}
		LL trm = (res * tim) % MOD;
		//cerr << trm << "?";
		sub = (sub + trm) % MOD;

	}

	LL ans = n*binpow(m, n, MOD) % MOD;

	ans -= sub;
	if (ans < 0) {
		ans += MOD;
	}

	cout << ans << "\n";

}