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

long long int MOD = 1000000007;
long long int MAX = 510000;

vector<long long int> fac(MAX), finv(MAX), inv(MAX);

void COMinit() {
  fac.at(0) = 1;
  fac.at(1) = 1;
  finv.at(0) = 1;
  finv.at(1) = 1;
  inv.at(1) = 1;
  for (int i = 2; i < MAX; i++) {
    fac.at(i) = fac.at(i - 1) * i % MOD;
    inv.at(i) = MOD - inv.at(MOD%i) * (MOD / i) % MOD;
    finv.at(i) = finv.at(i - 1) * inv.at(i) % MOD;
  }
}

int main() {
  long long int N, M;
  cin >> N >> M;
  COMinit();
  long long int ans = 0;
  for (int K = 0; K <= N; K++) {
    long long int A = fac.at(N) * (finv.at(K) * finv.at(N - K) % MOD) % MOD;
    long long int B = fac.at(M) * finv.at(M - K) % MOD;
    long long int C = fac.at(M - K) * finv.at(M - N) % MOD;
    long long int D = (A * B % MOD) * (C * C % MOD) % MOD;
    if (K % 2 != 0) D *=  -1;
    ans = (ans + D) % MOD;
  }
  if (ans < 0) ans += MOD;
  cout << ans << endl;
}