// E - NEQ
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
#define MOD 1000000007
#define madd(a,b) (((a)+(b))%MOD)
#define mmul(a,b) (((a)*(b))%MOD)
vl fac{1,1}, inv{0,1}, finv{1,1};

void finv_init(int n){
	for(int i=2; i<=n; ++i){
		fac.push_back(mmul(fac.back(), i));
		inv.push_back(madd(MOD, -mmul(inv[MOD%i], MOD/i)));
		finv.push_back(mmul(finv.back(), inv.back()));
	}
}

ll nPr(ll n, ll r){ return mmul(fac[n], finv[n-r]); }

int main(){
	int n, m; cin>>n>>m;
	finv_init(m);
	ll ans = 0;
	for(int d=0; d<=n; ++d){
		ll a = mmul(mmul(nPr(n, d), finv[d]), nPr(m-d, n-d));
		ans = madd(ans, d&1? -a:a);
	}
	ans = mmul(ans, nPr(m, n));
	cout<< madd(ans, MOD) <<endl;
}
