#include<iostream>
#include<cstdio>
using namespace std;
const int N=2002020,mod=1e9+7;
int n,m,fac[N],iv[N];
int fpow(int x,int y){
	int res=1;
	for(;y;y>>=1,x=1ll*x*x%mod)
		if(y&1)res=1ll*res*x%mod;
	return res;
}
int C(int x,int y){
	return 1ll*fac[x]*iv[y]%mod*iv[x-y]%mod;
}
int read(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int main()
{
	n=read(); m=read();
	fac[0]=iv[0]=1;
	for(int i=1;i<=max(n,m);i++)
		fac[i]=1ll*fac[i-1]*i%mod,iv[i]=fpow(fac[i],mod-2);
	int opt=1,ans=0;
	for(int i=0;i<=n;i++,opt*=-1){
		int wm=1ll*fac[m-i]*iv[m-i-(n-i)]%mod,lm=1ll*fac[m]*iv[m-i]%mod;
		int tmp=1ll*wm*wm%mod*lm%mod*C(n,i)%mod; ans=(ans+opt*tmp)%mod;
	} cout<<(ans%mod+mod)%mod<<endl;
	return 0;
}