//#include #include using namespace std; typedef long long ll; typedef pair p; const int INF = 1e9; const ll LINF = ll(1e18); const int MOD = 1000000007; const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl #define rep(i, n) for (int i = 0; i < n; i++) #define ALL(v) v.begin(), v.end() #define debug(v) \ cout << #v << ":"; \ for (auto x : v) \ { \ cout << x << ' '; \ } \ cout << endl; template bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } //cout< fac(1000001); //n!(mod M) vector ifac(1000001); //k!^{M-2} (mod M) ll mpow(ll x, ll n) { //x^n(mod M) ll ans = 1; while (n != 0) { if (n & 1) ans = ans * x % M; x = x * x % M; n = n >> 1; } return ans; } //conbination ll comb(ll a, ll b) { //aCb(mod M) if (a == 0 && b == 0) return 1; if (a < b || a < 0) return 0; ll tmp = ifac[a - b] * ifac[b] % M; return tmp * fac[a] % M; } ll fact_mod(ll n) { ll ret = 1; for (ll i = 2; i <= n; i++) ret = ret * (i % MOD) % MOD; return ret; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> m; fac[0] = 1; ifac[0] = 1; for (ll i = 0; i < 1000000; i++) { fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M) ifac[i + 1] = ifac[i] * mpow(i + 1, M - 2) % M; // k!^{M-2} (mod M) } ll ans=0; for(ll i=0;i<=m;i++){ if(i%2) ans-=comb(m,i)*mpow(m-i,n); else { ans += comb(m, i) * mpow(m - i, n); } ans=(ans+MOD)%MOD; } cout << ans<< "\n"; }