#include<iostream>
using namespace std;
const long mod=1e9+7;
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
long fac[5<<17],inv[5<<17];
int N,M;
long comb(int a,int b){return fac[a]*inv[b]%mod*inv[a-b]%mod;}
int main()
{
	cin>>N>>M;
	fac[0]=1;
	for(int i=1;i<=M;i++)fac[i]=fac[i-1]*i%mod;
	inv[M]=power(fac[M],mod-2);
	for(int i=M;i--;)inv[i]=inv[i+1]*(i+1)%mod;
	long ans=0;
	for(int i=0;i<=N;i++)
	{
		long now=comb(N,i)*comb(M-i,N-i)%mod*fac[N-i]%mod;
		if(i%2==0)ans+=now;
		else ans-=now;
	}
	ans=(ans%mod+mod)%mod;
	cout<<ans*fac[N]%mod*comb(M,N)%mod<<endl;
}
