#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <iomanip>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
void OutputVec(vector<bool> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
wGraph InputWGraph(ll N,ll M, bool isNeg){
    wGraph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        if(isNeg){
            c = -c;
        }
        G[a].push_back(make_pair(b,c));
        G[b].push_back(make_pair(a,c));
    }
    return G;
}
wGraph InputDWGraph(ll N, ll M,bool isNeg){
    wGraph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        if(isNeg){
            c = -c;
        }
        G[a].push_back(make_pair(b,c));
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}

void OutputGraph(wGraph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j].first <<"/" << G[i][j].second << ",";
        }
        cout << endl;
    }
}


vector<ll> Factorial(ll M, ll MOD){
    vector<ll> result = vector<ll>(M + 1);
    for(int i = 0; i <= M; i++){
        if(i == 0){
            result[i] = 1;
        }else{
            result[i] = result[i-1] * i % MOD;
        }
    }
    return result;
}

vector<ll> InvFact(ll M, ll MOD){
    vector<ll> result = vector<ll>(M + 1);
    vector<ll> inv = vector<ll> (M + 1);
    result[0] = 1;
    result[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < M; i++){
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        result[i] = result[i - 1] * inv[i] % MOD;
    }
    return result;
}

ll Combination(ll n,ll k,vector<ll>& fact, vector<ll>& invFact,ll MOD){
    //nCkを計算する
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fact[n] * (invFact[k] * invFact[n - k] % MOD) % MOD;
}

void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    ll N,M;
    cin >> N >> M;
    auto inv = InvFact(M+5,MOD7);
    auto fact = Factorial(M +5,MOD7);
    ll res = (fact[M] * inv[M-N]) % MOD7;
    vector<ll> memo(N + 1);
    memo[1] = M-N;
    memo[2] = (M-N+2) * (M-N+1) - (2 * (M-N+1) - 1);
    for (int i = 3; i <= N; ++i) {
        memo[i] = (M-N+i-1) * memo[i-1] + (i - 1) * memo[i-2];
        //cout << memo[3] << endl;
        memo[i] %= MOD7;
        //cout << memo[i] << endl;
    }
    //cout << res << endl;
    //cout << memo[N] << endl;
    cout << res * memo[N] % MOD7 << endl;

}


Measured memory_bytes: 14828