#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)

using namespace std;
template<int64_t M = 1000000007>
class ModInt {
public:
	ModInt() : val_(0) {};

	ModInt(int64_t val) {
		this->val_ = val;
		this->val_ %= M;
		while (this->val_ >= M) this->val_ -= M;
		while (this->val_ < 0)  this->val_ += M;
	}

	operator int64_t() const {
		return this->val_;
	}

	ModInt& operator += (int64_t val) {
		this->val_ += val;
		this->val_ %= M;
		while (this->val_ >= M) this->val_ -= M;
		while (this->val_ < 0) this->val_ += M;

		return *this;
	}

	ModInt& operator -= (int64_t val) {
		this->val_ -= val;
		this->val_ %= M;
		while (this->val_ >= M) this->val_ -= M;
		while (this->val_ < 0) this->val_ += M;

		return *this;
	}

	ModInt& operator *= (int64_t val) {
		this->val_ *= val;
		this->val_ %= M;

		return *this;
	}

	ModInt& operator /= (int64_t val) {
		ModInt v = ModInt::pow(val, M - 2);
		*this *= v;

		return *this;
	}

	ModInt operator + (int64_t v) const {
		ModInt ret = *this;
		return (ret += v);
	}

	ModInt operator - (int64_t v) const {
		ModInt ret = *this;
		return (ret -= v);
	}

	ModInt operator * (int64_t v) const {
		ModInt ret = *this;
		return (ret *= v);
	}

	ModInt operator / (int64_t v) const {
		ModInt ret = *this;
		return (ret /= v);
	}

	static ModInt pow(ModInt n, int64_t m) {
		if (m == 0) {
			ModInt ret(1);
			return ret;
		}
		if (m == 1) {
			return n;
		}

		ModInt v = pow(n, m / 2);
		ModInt ret = v * v;
		if (m & 1) {
			ret *= n;
		}
		return ret;
	}

	ostream& operator << (ostream& out) {
		out << this->val_;
		return out;
	}

private:
	int64_t val_;
};

template<int64_t M = 1000000007>
class NR {
public:
	NR() {};

	NR(int n) {
		this->factors_ = vector<ModInt<M>>(n + 1);
		this->finvs_ = vector<ModInt<M>>(n + 1);

		{
			ModInt<M> f = 1;
			this->factors_[0] = 1;
			FOR_LE(i, 1, n) {
				f *= i;
				this->factors_[i] = f;
			}
		}
		{
			ModInt<M> inv = ModInt<M>(1) / this->factors_[n];
			this->finvs_[n] = inv;
			FOR_DW(i, n - 1, 0) {
				inv *= i + 1;
				this->finvs_[i] = inv;
			}
		}
	}

	ModInt<M> NcrValue(int n, int k) {
		return this->factors_[n] * this->finvs_[n - k] * this->finvs_[k];
	}

	ModInt<M> NprValue(int n, int k) {
		return this->factors_[n] * this->finvs_[n - k];
	}

	ModInt<M> Factor(int n) {
		return this->factors_[n];
	}

	ModInt<M> Finv(int n) {
		return this->finvs_[n];
	}

private:
	vector<ModInt<M>> factors_;
	vector<ModInt<M>> finvs_;
};

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int64_t n, m; cin >> n >> m;

	NR<> nr(m);

	ModInt<> ans = nr.NprValue(m, n) * nr.NprValue(m, n);
	int64_t mul = -1;
	FOR_LE(i, 1, n) {
		ModInt<> cur = nr.NcrValue(n, i) * nr.NprValue(m, i) * nr.NprValue(m - i, n - i) * nr.NprValue(m - i, n - i);
		cur *= mul;
		ans += cur;
		mul *= -1;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 11096