#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;

#define INF (i64)1e18
#define MOD (i64)(1e9+7)
#define REP(i, n) for(i64 i = 0; i < n; i++)
#define RANGE(i, a, b) for(i64 i = a; i < b; i++)
#define EACH(v, e, p) for_each(v.begin(), v.end(), [](auto& e) p)

struct ModInt {
  i64 val;
  ModInt() {
    val = 0;
  }
  ModInt(i64 a) {
    val = mod(a);
  }
  inline i64 get() {
    return val;
  }
  inline operator i64(void) {
    return get();
  }
  inline i64 mod(i64 a) {
    a %= MOD;
    if (a < 0) a += MOD;
    return a;
  }
  inline ModInt &operator+=(ModInt a) {
    val = mod(val + a.val);
    return *this;
  }
  inline ModInt &operator-=(ModInt a) {
    val = mod(val - a.val);
    return *this;
  }
  inline ModInt &operator*=(ModInt a) {
    val = mod(val * a.val);
    return *this;
  }
  inline ModInt &operator/=(ModInt a) {
    return *this *= a.inv();
  }
  inline ModInt operator+(ModInt a) {
    return ModInt(*this) += a;
  }
  inline ModInt operator-(ModInt a) {
    return ModInt(*this) -= a;
  }
  inline ModInt operator*(ModInt a) {
    return ModInt(*this) *= a;
  }
  inline ModInt operator/(ModInt a) {
    return ModInt(*this) /= a;
  }
  inline ModInt operator-(void) {
    return ModInt(0 - val);
  }
  inline bool operator==(ModInt a) {
    return val == a.val;
  }
  inline bool operator!=(ModInt a) {
    return val != a.val;
  }
  inline ModInt &operator+=(i64 a) {
    return *this += ModInt(a);
  }
  inline ModInt &operator-=(i64 a) {
    return *this -= ModInt(a);
  }
  inline ModInt &operator*=(i64 a) {
    return *this *= ModInt(a);
  }
  inline ModInt &operator/=(i64 a) {
    return *this /= ModInt(a);
  }
  inline ModInt operator+(i64 a) {
    return ModInt(*this) += a;
  }
  inline ModInt operator-(i64 a) {
    return ModInt(*this) -= a;
  }
  inline ModInt operator*(i64 a) {
    return ModInt(*this) *= a;
  }
  inline ModInt operator/(i64 a) {
    return ModInt(*this) /= a;
  }
  inline bool operator==(i64 a) {
    return val == mod(a);
  }
  inline bool operator!=(i64 a) {
    return val != mod(a);
  }
  inline ModInt pow(i64 n) {
    ModInt a(*this);
    ModInt res = 1;
    while (n) {
      if (n & 1) {
        res *= a;
      }
      n >>= 1;
      a *= a;
    }
    return res;
  }
  inline ModInt inv() {
    return pow(MOD - 2);
  }
};

struct ModComb {
  i64 size;
  vector<ModInt> fact = {1};
  vector<ModInt> fact_inv = {1};
  ModComb(i64 n) {
    size = 1;
    RANGE(i, 1, n) {
      fact.push_back(fact[i-1] * i);
      fact_inv.push_back(fact[i].inv());
    }
  }
  inline void expand_fact(i64 n) {
    if (n <= size) return;
    RANGE(i, size, n) {
      fact.push_back(fact[i-1] * i);
      fact_inv.push_back(fact[i].inv());
    }
    size = n;
  }
  inline ModInt C(i64 n, i64 k) {
    if (k < 0 || k > n) return 0;
    expand_fact(n+1);
    return fact[n] * fact_inv[k] * fact_inv[n-k];
  }
  inline ModInt P(i64 n, i64 k) {
    if (k < 0 || k > n) return 0;
    expand_fact(n+1);
    return fact[n] * fact_inv[n-k];
  }
  inline ModInt H(i64 a, i64 b) {
    if (a == 0 && b == 0) return 1;
    if (a <= 0 || b < 0) return 0;
    expand_fact(a+b);
    return C(a+b-1, b);
  }
};

int main() {
  i64 n, m;
  cin >> n >> m;

  ModComb c(m+1);
  ModInt ans = 0;
  REP(k, n+1) {
    ModInt val = c.C(n, k) * c.P(m, k) * c.P(m-k, n-k) * c.P(m-k, n-k);
    if (k % 2 == 0) ans += val;
    else ans -= val;
  }

  cout << ans.val << endl;

  return 0;
}


Measured memory_bytes: 19092