#include <algorithm>
#include <chrono>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vi2;
typedef vector<vi2> vi3;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef vector<vll> vll2;
typedef vector<vll2> vll3;
typedef vector<bool> vb;

#define el '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repi(i, a, b) for (int i = a; i >= b; i--)
#define repeat(n) for (int i = 0; i < n; i++)
#define umap unordered_map
#define uset unordered_set
#define vec vector
#define loop(a) for (auto &x : a)
#define all(a) a.begin(), a.end()
#define mp make_pair
#define pb push_back

template <typename T>
void debug0(const T &value) {
    cerr << value << endl;
}

template <typename T, typename... Args>
void debug0(const T &value, const Args &... args) {
    cerr << value << ' ';
    debug0(args...);
}

#ifdef LOCAL
#define debug(...) debug0(__VA_ARGS__)
#else
#define debug(...)
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

namespace mod {

int extgcd(int a, int b, int &x, int &y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    int x1, y1;
    int d = extgcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}

int invmod(int a, int m) {
    int x, y;
    int g = extgcd(a, m, x, y);
    if (g != 1) {
        return -1;
    } else {
        x = (x % m + m) % m;
        return x;
    }
}

const int MODULE = 1e9 + 7;

int add(int x, int y) {
    x += y;
    while (x >= MODULE) {
        x -= MODULE;
    }
    return x;
}

int sub(int x, int y) {
    x -= y;
    while (x < 0) {
        x += MODULE;
    }
    return x;
}

int mul(int x, int y) {
    return (ll)x * y % MODULE;
}

int div(int x, int y) {
    return mul(x, invmod(y, MODULE));
}

vi fnv, fac;

void prep_mod(int n) {
    fnv = vi(n + 1);
    fac = vi(n + 1);
    fnv[0] = fac[0] = 1;
    rep(i, 1, n + 1) {
        fac[i] = mul(fac[i - 1], i);
        fnv[i] = mul(fnv[i - 1], invmod(i, MODULE));
    }
}

int comb(int total, int choose) {
    return mul(fac[total], mul(fnv[choose], fnv[total - choose]));
}

int perm(int total, int choose) {
    return mul(fac[total], fnv[total - choose]);
}

int power(int base, int exp) {
    if (exp == 0) {
        return 1;
    } else if (exp % 2 == 0) {
        return power(mul(base, base), exp / 2);
    } else {
        return mul(base, power(base, exp - 1));
    }
}
}  // namespace mod

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    mod::prep_mod(m);
    int ans = mod::power(mod::perm(m, n), 2);
    int ans0 = mod::perm(m, n);
    repi(i, m, m - n + 1) {
        ans0 = mod::mul(ans0, i);
    }
    rep(i, 1, n + 1) {
        int ans1 = mod::div(ans0, mod::comb(n, i - 1));
        ans1 = mod::div(ans1, m - i + 1);
        ans1 = mod::mul(ans1, mod::comb(n, i));
        if (i % 2 == 1) {
            ans = mod::sub(ans, ans1);
        } else {
            ans = mod::add(ans, ans1);
        }
        ans0 = ans1;
    }
    cout << ans << el;
}


Measured memory_bytes: 7104