#include using namespace std; using lint = long long int; struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; #define FOR(i, begin, end) for(int i=(begin);i<(end);i++) #define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) constexpr lint MOD = 1000000007; lint N, M; template struct ModInt { using lint = long long; int val; ModInt() : val(0) {} void _setval(lint v) { v = (v % mod) + mod; val = v >= mod ? v - mod : v; } ModInt(lint v) { _setval(v); } ModInt operator+(const ModInt &x) const { return ModInt((lint)val + x.val); } ModInt operator-(const ModInt &x) const { return ModInt((lint)val - x.val); } ModInt operator*(const ModInt &x) const { return ModInt((lint)val * x.val); } ModInt operator/(const ModInt &x) const { return ModInt((lint)val * x.inv().val); } ModInt operator-() const { return ModInt(-val); } ModInt &operator+=(const ModInt &x) { return *this = *this + x; } ModInt &operator-=(const ModInt &x) { return *this = *this - x; } ModInt &operator*=(const ModInt &x) { return *this = *this * x; } ModInt &operator/=(const ModInt &x) { return *this = *this / x; } bool operator==(const ModInt &x) { return val == x.val; } bool operator!=(const ModInt &x) { return val != x.val; } friend ostream &operator<<(ostream &os, const ModInt &x) { os << x.val; return os; } lint power(lint n) const { ModInt ans(1), tmp(val); while (n) { if (n & 1) ans *= tmp; tmp *= tmp; n /= 2; } return ans.val; } ModInt inv() const { return this->power(mod - 2); } ModInt fac() const { static vector facs; int l0 = facs.size(); if (l0 > this->val) return facs[this->val]; facs.resize(this->val + 1); for (int i = l0; i <= this->val; i++) facs[i] = (i == 0 ? 1 : facs[i - 1] * i); return facs[this->val]; } ModInt nCr(const ModInt &r) const { if (this->val < r.val) return ModInt(0); return this->fac() / ((*this - r).fac() * r.fac()); } }; using mint = ModInt; int main() { cin >> N >> M; if (M > N) cout << 0 << endl, exit(0); mint ans = 0; REP(m, M + 1) // 特定のm問に着手者がいない { mint tmp = mint(M).nCr(m) * mint(M - m).power(N); if (m & 1) ans -= tmp; else ans += tmp; } cout << ans << endl; }