#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
constexpr int MOD = 1e9+7, MX = 500005;
using ll = long long;
int n, m;
ll ans, cum;
ll exp(ll b, ll n){
	ll res = 1;
	for(; n; n/=2,(b*=b)%=MOD) if(n%2) (res *= b) %= MOD;
	return res;
}
ll fact[MX], invf[MX];
void setcomb(int n){
	fact[0] = 1;
	for(int i = 1; i <= n; i++) fact[i] = (fact[i-1] * i) % MOD;
	invf[n] =  exp(fact[n] ,MOD-2);
	for(int i = n; i > 0; i--) invf[i-1] = (invf[i] * i) % MOD;
}
inline ll comb(int a, int b){return fact[a] * invf[a-b] % MOD * invf[b] % MOD;}
int main(){
	scanf("%d%d", &n, &m);
	setcomb(m);
	ans = fact[n] * fact[m] % MOD * invf[m-n] % MOD * invf[m-n] % MOD;
	for(int i=0; i<=n; i++) (cum += invf[n-i] * invf[i] % MOD * fact[m-i] % MOD * (i&1 ? -1 : 1)) %= MOD;
	ans = ans * cum % MOD;
	if(ans < 0) ans += MOD;
	printf("%lld\n", ans);
}