class Ncrs(): def __init__(self, max_r, mod = 10**9+7) -> None: self.mod = mod self.fct, self.inv = [1] * (max_r+2), [1]* (max_r+2) for i in range(2, max_r+1): self.fct[i] = self.fct[i-1] * i % mod self.inv[max_r] = pow(self.fct[max_r], mod-2, mod) for i in range(max_r, 0,-1): self.inv[i-1] = self.inv[i] * i % mod def __call__(self, n, k) -> int: return self.nck(n, k) def nck(self, n, k) -> int: if k > n or n <0 or k <0: return 0 return self.fct[n] * self.inv[k] % self.mod * self.inv[n-k] % self.mod N, M = map(int, input().split()) res, w = 0, 1 mod = 10**9+7 ncr = Ncrs(M) for i in range(M, 0, -1): res += (w*ncr(M,i)*pow(i, N, mod))%mod res %= mod w *= -1 print(res)