#include #include using namespace std; using ll = long long; const ll MOD = (ll)1e9 + 7; //Combination Mod class Combination_Mod { public: vector fac, finv, inv; long long MOD; Combination_Mod(int N, long long mod) : fac(vector(N + 1)), finv(vector(N + 1)), inv(vector(N + 1)), MOD(mod) { fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1; for (int i = 2; i <= N; ++i) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } long long num(int n, int k) { return ((n < 0 || k < 0 || n < k) ? 0 : fac[n] * (finv[k] * finv[n - k] % MOD) % MOD); } }; //Pow_Mod O(log(n)) long long Pow_Mod(long long x, long long n, long long mod) { long long res = 1; for (; n > 0; n >>= 1, (x *= x) %= mod) if (n & 1) (res *= x) %= mod; return res; } int main() { ll N, M, ans = 0, sgn = 1; cin >> N >> M; Combination_Mod CM(M, MOD); for (ll i = M; 1 <= i; --i) { (ans += (MOD + sgn*((CM.num(M, i)*Pow_Mod(i, N, MOD)))) % MOD) %= MOD; sgn *= -1; } cout << ans << endl; return 0; }