N, M = map(int, input().split()) MOD = 10**9 + 7 fac = [1] * (M + 1) for i in range(1, M + 1): fac[i] = fac[i - 1] * i % MOD rev_fac = [1] * (M + 1) rev_fac[M] = pow(fac[M], MOD - 2, MOD) for i in range(M - 1, 0, -1): rev_fac[i] = rev_fac[i + 1] * (i + 1) % MOD comb = [1] * (M + 1) for i in range(1, M + 1): comb[i] = fac[M] * rev_fac[i] * rev_fac[M - i] % MOD if N < M: print(0) else: res = 0 for i in range(M): v = comb[i] * pow(M - i, N, MOD) if i % 2 == 0: res += v else: res -= v print(res % MOD)