#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; long long mod = 1000000007; long long m_pow(long long x, long long y) { long long ans = 1; while (y > 0) { if ((y & 1) == 1) { ans = ans * x % mod; } x = x * x % mod; y >>= 1; } return ans; } long long fac[200020], finv[200020], inv[200020]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < 200020; 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 COM(long long n, long long k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } int main() { COMinit(); long long n, m; cin >> n >> m; long long ans = 0; for (int i = m; i > 0; i--) { if ((m - i) % 2 == 0) { ans += m_pow(i, n) * COM(m, i) % mod; } else { ans -= m_pow(i, n) * COM(m, i) % mod; } ans %= mod; } cout << (ans + mod) % mod << endl; }