#include <iostream>

template<int mod>
struct modint {
    int x;
    modint() : x(0) {}
    modint(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    modint &operator+=(const modint &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    modint &operator-=(const modint &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    modint &operator*=(const modint &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    modint &operator/=(const modint &p) { *this *= p.inverse(); return *this; }
    modint operator-() const { return modint(-x); }
    modint operator+(const modint &p) const { return modint(*this) += p; }
    modint operator-(const modint &p) const { return modint(*this) -= p; }
    modint operator*(const modint &p) const { return modint(*this) *= p; }
    modint operator/(const modint &p) const { return modint(*this) /= p; }
    bool operator==(const modint &p) const { return x == p.x; }
    bool operator!=(const modint &p) const { return x != p.x; }
    modint inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
			t = a / b;
			a -= t * b;
			std::swap(a, b);
			u -= t * v;
			std::swap(u, v);
		}
        return modint(u);
    }
    modint pow(long long e){
        long long a = 1, p = x;
        while(e > 0) {
            if (e & 1) {a = (a * p) % mod; e--;}
            else {p = (p * p) % mod; e /= 2;}
        }
        return modint(a);
    }
    friend std::ostream &operator<<(std::ostream &os, const modint<mod> &p) {
        return os << p.x;
    }
    friend std::istream &operator>>(std::istream &is, modint<mod> &a) {
        long long x;
        is >> x;
        a = modint<mod>(x);
        return (is);
    }
};


#include <vector>

template<int mod>
struct permutation {
private :
    std::vector<modint<mod>> fact, ifact;
public :
    permutation(int n) : fact(n + 1), ifact(n + 1) {
        fact[0] = 1;
        for (int i = 1; i < n + 1; i++) fact[i] = (fact[i - 1] * i);
        ifact[n] = fact[n].inverse();
        for (int i = n; i > 0; i--) ifact[i - 1] = ifact[i] * i;
    }

    modint<mod> operator() (int n, int r) {
        if (r < 0 or r > n) return 0;
        return fact[n] * ifact[n - r];
    }

    constexpr const modint<mod> &operator[] (int i) const {
        return fact[i];
    }
};

template<int mod>
struct combination {
private :
    std::vector<modint<mod>> fact, ifact;
public : 
    combination(int n) : fact(n + 1), ifact(n + 1) {
        fact[0] = 1;
        for (int i = 1; i < n + 1; i++) fact[i] = (fact[i - 1] * i);
        ifact[n] = fact[n].inverse();
        for (int i = n; i > 0; i--) ifact[i - 1] = ifact[i] * i;
    }
    
	modint<mod> operator() (int n, int r) {
        if (r < 0 or r > n) return 0;
        return fact[n] * ifact[n - r] * ifact[r];
    }

    constexpr const modint<mod> &operator[] (int i) const {
        return fact[i];
    }

};

#include <bits/stdc++.h>

constexpr int MOD = 1'000'000'007;
constexpr int MAX = 1'000'000;

int main() {
	int n, m;
	std::cin >> n >> m;

	permutation<MOD> perm(MAX);
	combination<MOD> binom(MAX);

	modint<MOD> sum = 0;
	for (int k = 1; k <= n; k++) {
		modint<MOD> val = binom(n, k) * perm(m - k, n - k);
		if (k & 1) sum += val;
		else sum -= val;
	}

	modint<MOD> ans = perm(m, n) * perm(m , n) - perm(m, n) * sum;

	std::cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 18708