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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define MOD 1000000007

ll mod_inv(ll a)
{
  ll left = MOD-2;
  ll ret = 1;
  ll ks = a;
  while(left > 0)
  {
    if(left%2 == 1)
    {
      ret = ret*ks%MOD;
    }
    left /=2 ;
    ks = ks*ks%MOD;
  }
  return ret;
}

int main()
{
  ll n,m;
  cin >> n >> m;
  if(m < n) cout << 0 << "\n";
  else
  {
    int i;
    ll nck = 1;
    ll ks = 1;
    ll mpk = 1;
    ll pnk = 1;
    rep(i,n)
    {
      pnk = pnk*(m-i);
      pnk %= MOD;
    }
    ll ans = (nck*ks*mpk*pnk)%MOD*pnk%MOD;
    for(i=1;i<=n;i++)
    {
      nck = nck*(n+1-i)%MOD*mod_inv(i)%MOD;
      ks *= -1;
      mpk = mpk*(m+1-i)%MOD;
      pnk = pnk*mod_inv(m+1-i)%MOD;
      ans = ans+nck*(ks+MOD)%MOD*mpk%MOD*(pnk*pnk%MOD);
      ans %= MOD;
    }
    cout << ans << "\n";
  }
}
