#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll n;
ll m;
const ll mod = 1e9+7;
const ll maxn = 500005;
ll inv[maxn+3];
ll fac[maxn+3];

inline ll A(ll n,ll m){
    return fac[n]*inv[n-m]%mod;
}
inline ll C(ll n,ll m){
	return A(n,m)*inv[m]%mod;
}

int main(){
	//freopen("in.txt","r",stdin);
	cin>>n>>m;
	fac[0] = 1;
	fac[1] = 1;
	for(ll i=2;i<maxn;i++){
		fac[i] = i * fac[i-1];
		fac[i] %= mod;
	}
	inv[0]=1;inv[1]=1;      //inv[0]=1 !!! 
    for(ll i=2;i<=maxn;i++){
        inv[i]=(mod-mod/i)*inv[mod%i]%mod;
    }
    for(ll i=2;i<=maxn;i++){
        inv[i]=(inv[i]*inv[i-1])%mod;
    }
    ll ans =0;
    for(ll i=0;i<=n;i++){
    	ll tmp = C(n,i) * A(m-i,n-i);
    	tmp %= mod;
    	if(i%2==0){
    		ans += tmp;
		}else ans -= tmp;
		ans += mod;
		ans %= mod;
	}
	ans *= A(m,n);
	ans += mod;
	ans %= mod;
	cout<<ans<<endl;
	//cout<<tmp<<endl;
	return 0;
}
