//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*                                                    
      I ♥ CLARICE STARLING...                                                               
        EXPLAINATION BELOW->
        (MN)==mCn 
        PIE + Dearrangements
        First, let's count the number of ways to choose A, irrespective of B. 
        There are (MN) ways to choose the N integers to appear in A and N! ways to arrange them, so we have (MN)N! choices for A in total.
       Now, without loss of generality, assume the sequence A is simply 1,2,⋯,N, 
       since the number of choices for B doesn't depend on our sequence A. 
       We want to count the number of sequences B where there is no position i such that Bi=i.
      We do this using the principle of inclusion and exclusion.
      By PIE, we know that the number of sequences B where Bi≠i for all i is equal to the sum over all valid j of (−1)j times the number of ways to create a sequence B,
      where at least j positions i have Bi=i.
      Thus, it remains to compute the number of ways to compute the number of sequences B with at least j equal positions. 
     There are (Nj) ways to choose j positions where Bi=i. Then, it doesn't matter what we put in the remaining positions, so there are (M−jN−j) ways to choose the numbers and (N−j)! ways to arrange them.
       Thus, the total number of ways to ensure that at least j positions have Bi=i is (Nj)(M−jN−j)(N−j)!.
      By precomputing all relevant factorials and their modular inverses in O(M), we can compute the above product in O(1) for each j. We then sum these up using our PIE formula, giving us an O(N+M) solution. Since N≤M, this is simply O(M).
*/
//E-NEQ
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
const ll INF = (ll)2e18 + 77;
const int N=(int)1e6 + 1;
ll fact[N],invfact[N];
ll modularExponentiation(ll x,ll n,ll M)
{   
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
        result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
        return result;
}
void create_fact_modinv()
{
    int i;fact[0]=invfact[0]=1;
    fo(i,1,N)
    {
        fact[i]=(fact[i-1]*i)%MOD7;
        invfact[i]=modularExponentiation(fact[i],MOD7-2,MOD7);
    }
}
ll nCr(ll n,ll r)
{
    if(r>n)return 0;
    ll ans=fact[n];
    ans=(ans*invfact[r])%MOD7;
    ans=(ans*invfact[n-r])%MOD7;
    return ans;
}
void solve()
{
   ll N,M,i,ans=0,sign=1,term;cin>>N>>M;
   create_fact_modinv();
   foe(i,0,N)
   {
       term=sign;if(term<0)term+=MOD7;
       term=(term*nCr(N,i))%MOD7;
       term=(term*nCr(M-i,N-i))%MOD7;
       term=(term*fact[N-i])%MOD7;
       ans=(ans+term)%MOD7;
       sign*=(-1ll);
   }
   ans=(ans*nCr(M,N))%MOD7;
   ans=(ans*fact[N])%MOD7;
   cout<<ans%MOD7<<"\n";
}
int main()
{
   fastio
   //Test_cases
   solve();
  return 0;
}
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
// Syntax to create a min heap for priority queue priority_queue <int, vector<int>, greater<int>>; 
//for modinverse use modularexponention(x,M-2,M);
//for "each" subtraction from ans(ans-k) if(ans<0) do ans+=MOD,ans%=MOD
//vector<vector<int>>dp(201,vector<int>(n+1)); A way to initialize vector of vector
//If wrong on pretest 2 means logically wrong


/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/

Measured memory_bytes: 19220