#include <iostream>
#include <vector>

using namespace std;

const int Z = 1e9+7;

using vi = vector<int>;

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

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

    vi inv(m + 1), fac(m + 1), ifac(m + 1);
    for (int i = 0; i <= m; i++) {
        inv.at(i) = i <= 1 ? i : 1ll * (Z - Z / i) * inv.at(Z % i) % Z;
        fac.at(i) = i == 0 ? 1 : 1ll * fac.at(i - 1) * i % Z;
        ifac.at(i) = i == 0 ? 1 : 1ll * ifac.at(i - 1) * inv.at(i) % Z;
    }

    int ans = 0;
    for (int i = 0, p = 1; i <= n; i++, p *= -1) {
        ans = ((ans + 1ll * p * ifac.at(i) * ifac.at(n - i) % Z * fac.at(m - i)) % Z + Z) % Z;
    }

    ans = 1ll * ans * fac.at(m) % Z * fac.at(n) % Z * ifac.at(m - n) % Z * ifac.at(m - n) % Z;

    cout << ans << endl;

    return 0;
}
