#include<cstdio>
#define N 500000
#define LL long long
using namespace std;

LL mod=1e9+7;
LL fac[N+5],facinv[N+5];
LL ksm(LL x,LL y)
{
	LL res=1;
	while(y)
	{
		if(y&1) res=res*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return res;
}
LL A(int x,int y)
{
	return fac[x]*facinv[x-y]%mod;
}
LL C(int x,int y)
{
	return fac[x]*facinv[y]%mod*facinv[x-y]%mod;
}
int n,m;
int main()
{
	int i;
	fac[0]=1;
	for(i=1;i<=N;i++)
		fac[i]=fac[i-1]*i%mod;
	facinv[N]=ksm(fac[N],mod-2);
	for(i=N-1;i>=0;i--)
		facinv[i]=facinv[i+1]*(i+1)%mod;
	scanf("%d%d",&n,&m);
	LL ans=A(m,n);
	for(i=1;i<=n;i++)
	{
		if(i&1) ans=(ans-C(n,i)*A(m-i,n-i)%mod+mod)%mod;
		else ans=(ans+C(n,i)*A(m-i,n-i))%mod;
	}
	printf("%lld\n",ans*A(m,n)%mod);
	return 0;
}