#include <bits/stdc++.h>
const int maxm=1e6+5;
const long long oo=1e18;
const long long mod=1e9+7;
using namespace std;
int m,n;
long long lt(int a,int b)
{
if (b==0)
return 1;
long long tg=lt(a,b/2)%mod;
tg=(tg*tg)%mod;
if (b%2)
tg=(tg*a)%mod;
return tg;
}
long long Gt[maxm];
int main()
{
freopen("matrix.inp","r",stdin);
freopen("matrix.out","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> m >> n;
if (m==2)
cout << lt(m,n-1);
else
{
Gt[1]=1;
for (int i=2;i<=m;++i)
Gt[i]=(Gt[i-1]*i)%mod;
long long kq=1;
for (int i=2;i<m;++i)
{
kq=(kq*Gt[i])%mod;
kq=(kq*Gt[i])%mod;
}
kq=(kq*(lt(Gt[m],n-m+1)))%mod;
cout << kq;
}
return 0;
}