#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define fout(x) cout << fixed << setprecision(20) << x << endl
const int MOD = 1e9 + 7;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 1e-8;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

auto print = [](auto &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
};


template <int mod = 1000000007>
struct ModInt {
  long long x;
  ModInt(long long x = 0) : x((x % mod + mod) % mod) {}
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator++() const { return ModInt(x + 1); }
  ModInt operator--() const { return ModInt(x - 1); }
  ModInt inv() const { return pow(mod - 2); }
  ModInt operator+(const ModInt& m) const {
    ModInt res(*this);
    return res += m;
  }
  ModInt operator-(const ModInt& m) const {
    ModInt res(*this);
    return res -= m;
  }
  ModInt operator*(const ModInt& m) const {
    ModInt res(*this);
    return res *= m;
  }
  ModInt operator/(const ModInt& m) const {
    ModInt res(*this);
    return res /= m;
  }
  ModInt& operator+=(const ModInt& m) {
    x += m.x;
    x %= mod;
    return *this;
  }
  ModInt& operator-=(const ModInt& m) {
    x += mod - m.x;
    x %= mod;
    return *this;
  }
  ModInt& operator*=(const ModInt& m) {
    x *= m.x;
    x %= mod;
    return *this;
  }
  ModInt& operator/=(const ModInt& m) {
    if (m.x == 0) throw("divide by 0");
    return (*this) *= m.inv();
  }
  ModInt pow(long long p) const {
    if (p == 0) return 1;
    ModInt res = pow(p >> 1);
    res *= res;
    if (p & 1) res *= *this;
    return res;
  }
  bool operator==(const ModInt& m) const { return x == m.x; }
  bool operator!=(const ModInt& m) const { return x != m.x; }

  template <int I>
  friend std::ostream& operator<<(std::ostream& os, const ModInt<I>& m) {
    os << m.x << " (ModInt)";
    return os;
  }
  template <int I>
  friend std::istream& operator>>(std::istream& is, ModInt<I>& m) {
    long long tmp;
    is >> tmp;
    m = ModInt<I>(tmp);
    return is;
  }
};

using mint = ModInt<>;

template <int mod = 1000000007>
struct Combination {
  std::vector<long long> fac, finv, inv;
  Combination(const long long n)
      : fac(n + 1, 0), finv(n + 1, 0), inv(n + 1, 0) {
    for (long long i = 0; i < n + 1; ++i) {
      bool one_or_zero = i == 0 || i == 1;
      fac[i] = one_or_zero ? 1 : fac[i - 1] * i % mod;
      inv[i] = one_or_zero ? 1 : mod - inv[mod % i] * (mod / i) % mod;
      finv[i] = one_or_zero ? 1 : finv[i - 1] * inv[i] % mod;
    }
    inv[0] = 0;
  }
  long long operator()(const long long n, const long long r) {
    if (n < r || n < 0 || r < 0)
      return 0;
    else if (n == r || r == 0)
      return 1;
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod;
  }
  long long perm(const long long n, const long long r) {
    if (n < r || n < 0 || r < 0)
      return 0;
    else if (r == 0)
      return 1;
    return fac[n] * finv[n - r] % mod;
  }
};

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

  int n, m;
  cin >> n >> m;
  Combination<MOD> comb(max(n + 1, m + 1));

  mint ans = 0;
  for(int i = 1; i <= n; ++i) {
    if(i % 2 == 1) ans += mint(comb(n, i) * comb.perm(m - i, n - i));
    else ans -= mint(comb(n, i) * comb.perm(m - i, n - i));
  }
  ans *= mint(comb.perm(m, n));
  mint al(comb.perm(m, n) * comb.perm(m, n));
  ans = al - ans;

  out(ans.x);

  return 0;
}


Measured memory_bytes: 14656