#include<bits/stdc++.h>

int main(){
    using namespace std;
    constexpr unsigned long MOD = 1000000007;
    unsigned long N, M;
    cin >> N >> M;
    vector<unsigned long> inv(M + 1);
    inv[1] = 1;
    for(unsigned long i{2}; i <= M; ++i)inv[i] = MOD - MOD / i * inv[MOD % i] % MOD;
    unsigned long ans{1}, tmp{1};
    for(unsigned long i{1}; i <= N; ++i){
        (tmp *= N - i + 1) %= MOD;
        (tmp *= inv[i]) %= MOD;
        (tmp *= M - N + i) %= MOD;
        (ans = MOD + tmp - ans) %= MOD;
    }
    cout << ans * tmp % MOD << endl;
    return 0;
}