#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

const int MOD = 1e9 + 7;
long long fact[500005] = {1};

int power(int a, int n)
{
	long long ret = 1;
	while (n) {
		if (n & 1) ret = ret * a % MOD;
		a = 1LL * a * a % MOD;
		n >>= 1;
	}
	return ret;
}

long long comb(int n, int m)
{
	long long ret = fact[n] * power(fact[m], MOD - 2) % MOD;
	ret = ret * power(fact[n - m], MOD - 2) % MOD;
	return ret;
}

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= max(n, m); i++) {
		fact[i] = fact[i - 1] * i % MOD;
	}
	long long a = comb(m, n) * fact[n] % MOD;
	long long b = a;
	for (int i = 1; i <= n; i++) {
		long long t = comb(n, i) * comb(m - i, n - i) % MOD;
		t = t * fact[n - i] % MOD;
		if (i & 1) {
			b -= t;
			if (b < 0) b += MOD;
		} else {
			b += t;
			b %= MOD;
		}
	}
	long long ans = a * b % MOD;
	printf("%lld\n", ans);
	return 0;
}
