#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 1000000007;

ll F[500010], I[500010];

ll modpow(ll x, ll y) {
	ll ans = 1;
	while (y) {
		if (y & 1) 
			ans = ans * x % MOD;
		x = x * x % MOD;
		y /= 2;
	}
	return ans;
}

ll moddiv(ll x, ll y) {
	return x * modpow(y, MOD - 2) % MOD;
}

ll nCr(ll n, ll r) {
	return F[n] * I[r] % MOD * I[n - r] % MOD;
}

ll nPr(ll n, ll r) {
	return F[n] * I[n - r] % MOD;
}

int main() {
	F[0] = I[0] = 1;
	for (ll i = 1;i < 500010;i++) {
		F[i] = F[i - 1] * i % MOD;
		I[i] = modpow(F[i], MOD - 2);
	}
	ll N, M;
	cin >> N >> M;
	ll ans = 0;
	for (ll i = 0;i <= N;i++) {
		if (i & 1) {
			ans -= nCr(N, i) * nPr(M - i, N - i);
		}
		else {
			ans += nCr(N, i) * nPr(M - i, N - i);
		}
		ans %= MOD;
	}
	if (ans < 0)ans += MOD;
	cout << ans * nPr(M, N) % MOD << endl;
}