#include <stdio.h>
long long p = 1000000007;
long long n, m, a, b, c;
long long inv[500001];
long long kai[500001];
long long iai[500001];
void makeinv(void) {
	long long arraynumber = sizeof inv / sizeof inv[0];
	inv[1] = 1;
	for (int invcount = 2; invcount < arraynumber; invcount++) {
		inv[invcount] = p - inv[p % invcount] * (p / invcount) % p;
	}
}
int main() {
	makeinv();
	kai[0] = 1;
	iai[0] = 1;
	for (long long i = 1; i <= 500000; i++) {
		kai[i] = kai[i - 1] * i % p;
		iai[i] = iai[i - 1] * inv[i] % p;
	}
	scanf("%lld%lld", &n, &m);
	a = kai[n] * kai[m] % p;
	a *= iai[m - n];
	a %= p;
	a *= iai[m - n];
	a %= p;
	for (long long i = 0; i <= n; i++) {
		b = 1;
		if (i % 2)b = p - 1;
		b *= kai[m - i];
		b %= p;
		b *= iai[i];
		b %= p;
		b *= iai[n - i];
		b %= p;
		c += b;
		c %= p;
	}
	printf("%lld\n", a * c % p);
}