#include using namespace std; template T inverse(T a, T m) { T u = 0, v = 1; while (a != 0) { T t = m / a; m -= t * a; u -= t * v; std::swap(a, m); std::swap(u, v); } assert(m == 1); return u; } template class Modular { public: using Type = typename std::decay::type; constexpr Modular() : value() {} template Modular(const U &x) : value(normalize(x)) {} template Type normalize(const U &x) { Type v; if (-mod() <= x && x < mod()) { v = static_cast(x); } else { v = static_cast(x % mod()); } if (v < 0) v += mod(); return v; } const Type &operator()() const { return value; } template explicit operator U() const { return static_cast(value); } constexpr static Type mod() { return T::value; } Modular &operator+=(const Modular &rhs) { if ((value += rhs.value) >= mod()) value -= mod(); return *this; } Modular &operator-=(const Modular &rhs) { if ((value -= rhs.value) < 0) value += mod(); return *this; } template Modular &operator+=(const U &rhs) { return *this += Modular(rhs); } template Modular &operator-=(const U &rhs) { return *this -= Modular(rhs); } Modular &operator++() { return *this += 1; } Modular &operator--() { return *this -= 1; } Modular operator++(int) { Modular res(*this); *this += 1; return res; } Modular operator--(int) { Modular res(*this); *this -= 1; return res; } template typename enable_if::Type, int>::value, Modular>::type & operator*=(const Modular &rhs) { value = normalize(static_cast(value) * static_cast(rhs.value)); return *this; } template typename enable_if< std::is_same::Type, int64_t>::value || std::is_same::Type, std::int_fast64_t>::value, Modular>::type & operator*=(const Modular &rhs) { value = normalize(static_cast<__int128>(value) * static_cast<__int128>(rhs.value)); return *this; } Modular &operator/=(const Modular &rhs) { return *this *= Modular(inverse(rhs.value, mod())); } template friend bool operator==(const Modular &lhs, const Modular &rhs); template friend bool operator<(const Modular &lhs, const Modular &rhs); template friend bool operator>(const Modular &lhs, const Modular &rhs); template friend std::istream &operator>>(std::istream &stream, Modular &rhs); template friend std::ostream &operator<<(std::ostream &stream, const Modular &rhs); private: Type value; }; template bool operator==(const Modular &lhs, const Modular &rhs) { return lhs.value == rhs.value; } template bool operator==(const Modular &lhs, U rhs) { return lhs == Modular(rhs); } template bool operator==(U lhs, const Modular &rhs) { return Modular(lhs) == rhs; } template bool operator!=(const Modular &lhs, const Modular &rhs) { return !(lhs == rhs); } template bool operator!=(const Modular &lhs, U rhs) { return !(lhs == rhs); } template bool operator!=(U lhs, const Modular &rhs) { return !(lhs == rhs); } template bool operator<(const Modular &lhs, const Modular &rhs) { return lhs.value < rhs.value; } template bool operator>(const Modular &lhs, const Modular &rhs) { return lhs.value > rhs.value; } template Modular operator+(const Modular &lhs, const Modular &rhs) { return Modular(lhs) += rhs; } template Modular operator+(const Modular &lhs, U rhs) { return Modular(lhs) += rhs; } template Modular operator+(U lhs, const Modular &rhs) { return Modular(lhs) += rhs; } template Modular operator-(const Modular &lhs, const Modular &rhs) { return Modular(lhs) -= rhs; } template Modular operator-(const Modular &lhs, U rhs) { return Modular(lhs) -= rhs; } template Modular operator-(U lhs, const Modular &rhs) { return Modular(lhs) -= rhs; } template Modular operator*(const Modular &lhs, const Modular &rhs) { return Modular(lhs) *= rhs; } template Modular operator*(const Modular &lhs, U rhs) { return Modular(lhs) *= rhs; } template Modular operator*(U lhs, const Modular &rhs) { return Modular(lhs) *= rhs; } template Modular operator/(const Modular &lhs, const Modular &rhs) { return Modular(lhs) /= rhs; } template Modular operator/(const Modular &lhs, U rhs) { return Modular(lhs) /= rhs; } template Modular operator/(U lhs, const Modular &rhs) { return Modular(lhs) /= rhs; } template Modular power(const Modular &a, const U &b) { assert(b >= 0); Modular x = a, res = 1; U n = b; while (n > 0) { if (n & 1) res *= x; x *= x; n >>= 1; } return res; } template std::istream &operator>>(std::istream &stream, Modular &rhs) { typename common_type::Type, int64_t>::type x; stream >> x; rhs = Modular(x); return stream; } template std::ostream &operator<<(std::ostream &stream, const Modular &rhs) { stream << rhs.value; return stream; } constexpr int mod = 1000000007; using mint = Modular::type, mod>>; template class Combination { private: vector f, invf; public: Combination(int n) : f(n + 1, 1), invf(n + 1, 1) { for (int i = 1; i < n + 1; i++) { f[i] = f[i - 1] * i; } invf[n] /= f[n]; for (int i = n; i > 0; i--) { invf[i - 1] = invf[i] * i; } } // nCr const T operator()(int n, int r) const { if (r < 0 || n < r) return 0; return f[n] * invf[r] * invf[n - r]; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); int N, M; cin >> N >> M; Combination comb(N); vector memo(M + 1, 0); for (int i = 1; i < M + 1; i++) { memo[i] = comb(M, i) * power(static_cast(i), N) - memo[i - 1]; } cout << memo[M] << '\n'; return 0; }