#include<bits/stdc++.h>
using namespace std;
#define IO {ios_base::sync_with_stdio(false); cin.tie(0);}
#define ll long long
#define pi pair<ll,ll>
ll a[600008];
string s, s1;
map<ll, ll>mp;

ll f(ll n, ll b, ll mod)
{
    ll ans=1, aa;
    if(!b) return 1;
    if(b%2) ans=n;
    aa=f(n,b/2,mod); return ((aa*aa)%mod * ans)%mod;
}
int main()
{
    IO;
    ll i, j, k=0, l, n, m, t, h, cnt=0, curr, mx, mod=1e9+7;
    cin>>n>>m; a[0]=1;
    for(i=1; i<=m; i++) a[i]=(a[i-1]*i)%mod;
    l=1;
    for(i=0; i<=n; i++){
        j = ((a[n-i]*a[i])%mod*a[m-n])%mod;
        j = f(j,mod-2,mod); j = ((j*a[n])%mod*a[m-i])%mod; k=(k+l*j)%mod; l*=-1;
    }
    j = f(a[m-n],mod-2,mod); j =(j*a[m])%mod; j = (j*k)%mod;
    cout<<(j+mod)%mod<<endl;
    return 0;
}
