MOD = 10**9 + 7 list_size = 100001 f_list = [1] * list_size f_r_list = [1] * list_size for i in range(list_size - 1): f_list[i + 1] = int((f_list[i] * (i + 2)) % MOD) f_r_list[-1] = pow(f_list[-1], MOD - 2, MOD) for i in range(2, list_size + 1): f_r_list[-i] = int((f_r_list[-i + 1] * (list_size + 2 - i)) % MOD) def comb(n, r): if n < r: return 0 elif n == 0 or r == 0 or n == r: return 1 else: return (((f_list[n - 1] * f_r_list[n - r - 1]) % MOD) * f_r_list[r - 1]) % MOD n, m = map(int, input().split()) ans = 0 for i in range(m, 0, -1): if (m%2) == (i%2): ans += pow(i, n, MOD) * comb(m, i) ans %= MOD else: ans -= pow(i, n, MOD) * comb(m, i) ans %= MOD print(ans)