#include <bits/stdc++.h>
using namespace std;
#define Sz(a) ((int)(a).size())
const int maxn = 500009;
const int MOD = 1e9 + 7;
int64_t fac[maxn],inv[maxn];
int64_t pw(int64_t a,int64_t b){
  int64_t c=1;
  while(b){
    if(b&1ll)c=c*a%MOD;
    a=a*a%MOD;
    b>>=1;
  }
  return c;
}
int64_t C(int a,int b){
  return fac[a]*inv[b]%MOD*inv[a-b]%MOD;
}
int64_t A(int a,int b){
  return fac[a]*inv[a-b]%MOD;
}
int main(){
#ifdef LOCAL
  freopen("a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false),cout.tie(0),cin.tie(0);
  int n,m;cin>>n>>m;
  fac[0]=1;
  for(int i=1;i<maxn;++i)fac[i]=fac[i-1]*i%MOD;
  inv[maxn-1]=pw(fac[maxn-1],MOD-2);
  for(int i=maxn-2;i>=0;--i)inv[i]=inv[i+1]*(i+1)%MOD;
  int64_t res=0;
  for(int i=0;i<=n;++i){
    if(i&1){
      (res+=MOD-C(n,i)*A(m-i,n-i)%MOD)%=MOD;
    }else{
      (res+=C(n,i)*A(m-i,n-i)%MOD)%=MOD;
    }
  }
  res=res*A(m,n)%MOD;
  cout<<res;
  return 0;
}
//2020.06.27 20:41:25
