MOD = 1_000_000_007 n,m = gets.split.map(&:to_i) def powmod(v, p) return 1 if p == 0 return v if p == 1 ret = powmod(v, p / 2) ret *= ret ret %= MOD p % 2 == 1 ? ret * v % MOD : ret end ans = 0 sgn = 1 comb = 1 m.downto(1) { |i| ans += sgn * powmod(i, n) * comb sgn *= -1 comb *= i * powmod(m + 1 - i, MOD - 2) comb %= MOD } puts ans % MOD