#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5e5 + 10;
int n, m;
const ll mod = 1e9 + 7;
ll ans;
ll fac[maxn], inv[maxn], facinv[maxn], bin[maxn];
void pre()
{
	fac[0] = 1; for(int i = 1; i < maxn; ++i) fac[i] = fac[i - 1] * i % mod;
	inv[1] = 1; for(int i = 2; i < maxn; ++i) inv[i] = (mod - mod / i) * inv[mod % i] % mod;
	facinv[0] = 1; for(int i = 1; i < maxn; ++i) facinv[i] = facinv[i - 1] * inv[i] % mod;
	bin[0] = 1; for(int i = 1; i < maxn; ++i) bin[i] = bin[i - 1] * 2 % mod;
}
ll square(ll x) { return x * x % mod;}
ll C(int n, int m) { return n < m ? 0 : fac[n] * facinv[m] % mod * facinv[n - m] % mod;}
int main()
{
	pre();
	scanf("%d%d", &n, &m);
	ll flag = -1;
	for(int i = 0; i <= n; ++i)
	{
		flag *= -1;
		ll ret = flag * C(n, i) * C(m, i) % mod * fac[i] % mod * square(C(m - i, n - i) * fac[n - i] % mod);
		ans = (ans + ret) % mod;
	}
	cout << (ans + mod) % mod << endl;
	return 0;
}
	
	