#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define mp make_pair
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
const int N = 5e5 + 1;
int n , m , fact[N] , inv[N];
int mult(ll a , ll b){
	return (a*b)%M;
}
int fp(ll a , ll b){
	int res = 1;
	while(b > 0){
		if(b&1)res = mult(res , a);
		b/=2;
		a = mult(a , a);
	}
	return res;
}
int nck(ll n , ll k){
	//if(k > n)return 1;
	return mult(fact[n] , mult(inv[n-k] , inv[k]));
}
int npk(ll n , ll k){
	return mult(fact[n] , inv[n-k]);
}
int main(){
	cin >> n >> m;
	fact[0] = inv[0] = 1;
	for (int i = 1; i <= N-1; ++i){
		fact[i] = mult(fact[i-1] , i);
		inv[i] = fp(fact[i] , M-2);
	}
	int res = 0;
	//cout << nck(5 , 2) <<endl;
	for (int i = 0; i <= n; ++i){
		int x = mult(nck(n , i) , npk(m-i , n-i));
		if(i&1) res = (res - x + M)%M;
		else res = (res + x)%M;
		//cout << res <<endl;
	}
	cout << mult(npk(m,n) , res);
	

}	