#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int MXN = 5e5 + 1;
const int MOD = 1e9 + 7;
int fact[MXN];
int add(int x, int y) {return (x+y) % MOD;}
int mul(int x, int y) {return (x*1ll*y) % MOD;}
int bp(int x, int y) {
	int ans = 1;
	while (y) {
		if (y&1) ans = mul(ans, x);
		x = mul(x, x);
		y >>= 1;
	}
	return ans;
}
int inv(int x) {return bp(x, MOD-2);}
int cmb(int n, int k) {
	return mul(fact[n], inv(mul(fact[k], fact[n-k])));
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n, m;
	cin >> n >> m;
	fact[0] = 1;
	for (int i=1; i<=m; i++) fact[i] = mul(fact[i-1], i);
	int ans = 0;
	for (int i=0; i<=n; i++) {
		int same = mul(mul(cmb(n, i), cmb(m, i)), fact[i]);
		int tmp = cmb(m-i, n-i);
		int diff = mul(mul(tmp, tmp), mul(fact[n-i], fact[n-i]));
		int cur = mul(same, diff);
		if (i&1) {
			ans = add(ans+MOD, -cur);
		}
		else {
			ans = add(ans, cur);
		}
	}
	cout << ans << '\n';
}