#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl

template<int mod> struct ModInt {
    int64_t x;
    ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (y % mod + mod) % mod) {}

    ModInt &operator+=(const ModInt &a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator-=(const ModInt &a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &a) {
        x = 1LL * x * a.x % mod;
        return *this;
    }

    ModInt &operator/=(const ModInt &a) {
        *this *= a.inverse();
        return *this;
    }

    ModInt operator-() const {
        return ModInt(-x);
    }

    ModInt operator+(const ModInt a) const {
        return ModInt(*this) += a;
    }

    ModInt operator-(const ModInt a) const {
        return ModInt(*this) -= a;
    }

    ModInt operator*(const ModInt a) const {
        return ModInt(*this) *= a;
    }

    ModInt operator/(const ModInt a) const {
        return ModInt(*this) /= a;
    }

    bool operator==(const ModInt a) const {
        return x == a.x;
    }

    bool operator!=(const ModInt a) const {
        return x != a.x;
    }

    ModInt pow(int64_t k) const {
        ModInt ret(1), mul(x);
        while (k > 0) {
            if (k & 1) ret *= mul;
            mul *= mul;
            k >>= 1;
        }
        return ret;
    }

    ModInt inverse() const {
        return pow(mod - 2);
    }

    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }
};

const int MOD = 1e9+7;

using modint = ModInt<MOD>;

template <typename ModInt> class ModCalc {
private:
    vector<ModInt> fact, finv, inv_;

    void init(int n) {
        int mx = n*2+10;
        fact = vector<ModInt>(mx);
        finv = vector<ModInt>(mx);
        inv_ = vector<ModInt>(mx);

        fact[0] = fact[1] = ModInt(1);
        finv[0] = finv[1] = ModInt(1);
        inv_[1] = ModInt(1);
        FOR (i, 2, mx) {
            fact[i] = fact[i-1]*ModInt(i);
            inv_[i] = ModInt(i).inverse();
            finv[i] = finv[i-1]*inv_[i];
        }
    }

public:
    ModCalc() {}
    ModCalc(int n) { init(n); }

    ModInt nCk (int n, int k) {
        if (n < k || k < 0 || n < 0) return 0;
        return fact[n]*finv[k]*finv[n-k];
    }

    ModInt nHk (int n, int k) {
        return nCk(n-1+k, n-1);
    }

    ModInt nPk (int n, int k) {
        if (n < k || k < 0 || n < 0) return 0;
        return fact[n]*finv[n-k];
    }

    ModInt factorial(int n) {
        return fact[n];
    }

    ModInt stirling(ll n, int k) {
        ll ret = 0;
        FOR (i, 1, k+1)
            ret += ModInt(-1).pow(k-i) * nCk(k, i) * ModInt(i, n);
        return ret;
    }
};

const int MAX = 5e5+10;

ModCalc<modint> modcalc(MAX);
ll N, M;

modint solve() {
    modint ret = modcalc.nPk(M, N);

    FOR (k, 1, N+1) {
        ret += modcalc.nCk(N, k) * modcalc.nPk(M-k, N-k) * modint(-1).pow(k);
    }

    return ret * modcalc.nPk(M, N);
}

int main() {
    cout << fixed << setprecision(15);
    cin >> N >> M;
    cout << solve() << endl;
}

Measured memory_bytes: 26540