#include <iostream>
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    // 前処理
    COMinit();

    int n,m;cin>>n>>m;
    long long ans=fac[m]*finv[m-n]%MOD*fac[m]%MOD*finv[m-n]%MOD,sum=0;
    for(int i=1;i<=n;++i){
        long long k=COM(n,i)*fac[m]%MOD*finv[m-n]%MOD*fac[m-i]%MOD*finv[m-n]%MOD;
        if(i%2==0)sum-=k;
        else sum+=k;
        while(sum<0)sum+=MOD;
        sum%=MOD;
    }
    ans-=sum;
    while(ans<0)ans+=MOD;
    cout<<ans<<endl;
}