#include #define M_PI 3.14159265358979323846 // pi using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair P; typedef tuple t3; typedef tuple t4; #define rep(a,n) for(ll a = 0;a < n;a++) #define repi(a,b,n) for(ll a = b;a < n;a++) template void chmax(T& reference, T value) { reference = max(reference, value); } template void chmaxmap(map& m, T key, T value) { if (m.count(key)) { chmax(m[key], value); } else { m[key] = value; } } template void chmin(T& reference, T value) { reference = min(reference, value); } #include using namespace atcoder; typedef modint1000000007 mint; struct Point { ll x, y; bool operator <(const Point& p) const { return x < p.x || (x == p.x && y < p.y); } }; struct ConvexHullRunner { typedef ll coord_t; typedef ll coord2_t; coord2_t cross(const Point& O, const Point& A, const Point& B) { return (A.x - O.x) * (B.y - O.y) - (A.y - O.y) * (B.x - O.x); } vector convex_hull(vector P) { size_t n = P.size(), k = 0; if (n <= 3) return P; vector H(2 * n); sort(P.begin(), P.end()); for (size_t i = 0; i < n; ++i) { while (k >= 2 && cross(H[k - 2], H[k - 1], P[i]) <= 0) k--; H[k++] = P[i]; } for (size_t i = n - 1, t = k + 1; i > 0; --i) { while (k >= t && cross(H[k - 2], H[k - 1], P[i - 1]) <= 0) k--; H[k++] = P[i - 1]; } H.resize(k - 1); return H; } }; constexpr ll mod = 1000000007; constexpr ll mpow(ll x, ll n) { ll ans = 1; x %= mod; while (n != 0) { if (n & 1) ans = ans * x % mod; x = x * x % mod; n = n >> 1; } return ans; } constexpr ll inv_mod(ll a) { return mpow(a, mod - 2); } class Factorial { private: vector fac; vector ifac; public: Factorial(ll N) { fac.push_back(1); for (int i = 0; i < N; i++) fac.push_back(fac[i] * (i + 1) % mod); ifac.resize(N + 1); ifac[N] = inv_mod(fac[N]); for (int i = 0; i < N; i++) ifac[N - 1 - i] = (ifac[N - i] * (N - i)) % mod; } ll fact(ll a) { return fac[a]; } ll ifact(ll a) { return ifac[a]; } ll cmb(ll a, ll b) { if (a == 0 && b == 0) return 1; if (a < b || a < 0 || b < 0) return 0; ll tmp = ifact(a - b) * ifact(b) % mod; return tmp * fac[a] % mod; } ll per(ll a, ll b) { if (a == 0 && b == 0) return 1; if (a < b || a < 0 || b < 0) return 0; return fac[a] * ifac[a - b] % mod; } }; int main() { ll n, m; cin >> n >> m; mint sum = 0; Factorial f(m + 10); int s = 1; for (int i = m; i >= 1; i--) { mint x = mpow(i, n); mint y = f.cmb(m, i); sum += x * y * s; s *= -1; } cout << sum.val() << endl; return 0; }