def mod_build(n, mod) : fact = [1]*(n+1) inv_fact = [1]*(n+1) for i in range(1,n+1): fact[i] = fact[i-1]*i %mod inv_fact[n] = pow(fact[n],mod-2,mod) for i in range(n,0,-1): inv_fact[i-1] = inv_fact[i]*i %mod return fact, inv_fact def comb(n,k,fact,inv_fact, mod) : if n<0 or k<0 or k>n : return 0 return fact[n]*inv_fact[k]*inv_fact[n-k]%mod def solve() : n, m = map(int, input().split()) if n == 1 : return 1 mod = 1000000007 fact, inv_fact = mod_build(m,mod) i = m//2 ans = 0 idx = [i+n*j for j in range(-m,m) if i+n*j>=0 and i+n*j <=n ] for j in idx : ans += comb(m,j,fact,inv_fact,mod) return ans print(solve())