#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll powermd(ll x,  int y,	ll p)
{
    ll res = 1;     // Initialize result
 
    x = x % p; // Update x if it is more than or
                // equal to p
  
    // if (x == 0) return 0; // In case x is divisible by p;
 
    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;
 
        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
void solve(){
	ll n,p;
	cin>>n>>p;
	cout<<(powermd(p-2,n-1,1000000007)*(p-1))%1000000007;
}
int main(){
	int t;
	t=1;
    while(t--) {
    	solve();
	}
}
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int N, K;
int dp[3005][3005];
const int mod = 998244353;

int f(int n, int k) {
	if(n < k) return 0;
	if(k == 0) return (n == 0);
	if(~dp[n][k]) return dp[n][k];

	int ret = 0;
	ret += f(n - 1, k - 1);
	ret %= mod;
	ret += f(n, 2 * k);
	ret %= mod;

	return dp[n][k] = ret;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);

	memset(dp, -1, sizeof(dp));
	cin >> N >> K;
	cout << f(N, K) << endl;

	return 0;
}	