#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
const ll INF = 2e18;
const int inf = 1e9+10;
const int maxN = 5e5 + 10;
const int maxD = 15;
const int maxH = 100; 
const int MOD = 1e9+7;


ll h[maxN];
ll power(ll x,ll p)
{
	if(p == 0)
	{
		return 1;
	}
	ll t = power(x,p/2);
	t = t*t%MOD;
	if(p%2 == 1)
	{
		t = t*x%MOD;
	}
	return t;
}
ll C(int n,int m)
{
	ll ans = h[n] * power(h[m],MOD-2) %MOD * power(h[n-m],MOD-2)%MOD;
	return ans;
}
ll rev(ll x)
{
	return power(x,MOD-2);
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	h[0] = 1;
	for(int i=1;i<=m;i++)
	{
		h[i] = (h[i-1]*i)%MOD; 
	}
	ll ans = 0;
	for(int k=0;k<=n;k++)
	{
		ll res = C(m,n) * C(n,k)%MOD * h[n] %MOD * h[m-k] %MOD * rev(h[m-n])%MOD;
		if(k%2)
		{
			ans -= res;
		}
		else
		{
			ans += res; 
		}
		ans = (ans+MOD)%MOD;
	}
	cout<<ans<<endl;
	return 0;
}