# include using namespace std; typedef long long ll; const ll mod = 1e9 + 7; const int N = 100010; ll n, m, res; ll fac[N], inv[N], finv[N]; constexpr ll INF=1e16; void init() { fac[0] = fac[1] = inv[0] = inv[1] = finv[0] = finv[1] = 1; for (int i = 1; i < N; i++) fac[i] = fac[i - 1] * i % mod; for (int i = 2; i < N; i++) inv[i] = (mod - mod / i) * inv[mod % i] % mod; for (int i = 2; i < N; i++) finv[i] = finv[i - 1] * inv[i] % mod; } ll C(ll x, ll y) { if (x < y) return 0; return fac[x] * finv[x - y] % mod * finv[y] % mod; } ll ksm(ll x, ll y) { ll res; res = 1; while (y) { res = (y & 1) ? res * x % mod : res; x = x * x % mod; y >>= 1; } return res; } int main() { init(); scanf("%lld%lld", &n, &m); if (n < m) printf("0\n"), exit(0); res = 0; for (int i = 0; i <= m; i++) { if ((m - i) & 1) res = (res - C(m, i) * ksm(i, n) % mod + mod) % mod; else res = (res + C(m, i) * ksm(i, n) % mod) % mod; } printf("%lld\n", res); return 0; }