MOD = 10 ** 9 + 7 n, m = map(int, input().split()) fact = [1 for _ in range(n + 1)] inv = [1 for _ in range(n + 1)] ifact = [1 for _ in range(n + 1)] for x in range(2, n + 1): fact[x] = (fact[x - 1] * x) % MOD inv[x] = (- (MOD // x) * inv[MOD % x]) % MOD ifact[x] = (ifact[x - 1] * inv[x]) % MOD ans = 0 for i in range(m + 1): if (m - i) % 2 == 0: ans = (ans + fact[m] * ifact[m - i] * ifact[i] * pow(i, n, MOD)) % MOD else: ans = (ans - fact[m] * ifact[m - i] * ifact[i] * pow(i, n, MOD)) % MOD print(ans)