import sys MOD = 10**9 + 7 # It's better to precompute factorials outside if multiple test cases, # but for one test case, it can be inside main/solve. # Max M is 10^6. Factorials up to M. MAX_FACTORIAL_N = 10**6 + 5 # A bit of margin fact = [1] * MAX_FACTORIAL_N inv_fact = [1] * MAX_FACTORIAL_N def precompute_factorials(): for i in range(1, MAX_FACTORIAL_N): fact[i] = (fact[i - 1] * i) % MOD inv_fact[MAX_FACTORIAL_N - 1] = pow(fact[MAX_FACTORIAL_N - 1], MOD - 2, MOD) for i in range(MAX_FACTORIAL_N - 2, -1, -1): # From MAX_VAL-2 down to 0 inv_fact[i] = (inv_fact[i + 1] * (i + 1)) % MOD precompute_factorials() # Precompute once globally def nCr_mod(n, r): if r < 0 or r > n: return 0 if n >= MAX_FACTORIAL_N: # Should not happen with M <= 10^6 # Fallback or error, this indicates MAX_FACTORIAL_N is too small # For competitive programming, ensure MAX_FACTORIAL_N covers max possible n raise ValueError("n is too large for precomputed factorials") num = fact[n] den = (inv_fact[r] * inv_fact[n - r]) % MOD return (num * den) % MOD def main(): N, M = map(int, sys.stdin.readline().split()) if N == 1: sys.stdout.write(str(1) + "\n") return if N == 2: # For M >= 1, dp[M][1] = 2^(M-1) ans = pow(2, M - 1, MOD) sys.stdout.write(str(ans) + "\n") return # Case N > 2: C(M, floor(M/2)) k = M // 2 ans = nCr_mod(M, k) sys.stdout.write(str(ans) + "\n") if __name__ == '__main__': main()