n = 10005 mod = 10 ** 9 + 7 fact = [1] * (n + 1) invfact = [1] * (n + 1) for i in range(1, n): fact[i + 1] = ((i+1) * fact[i]) % mod invfact[n] = pow(fact[n], mod - 2, mod) for i in range(n - 1, -1, -1): invfact[i] = invfact[i + 1] * (i + 1) % mod def comb(n, r): if n < 0 or r < 0 or n - r < 0: return 0 return fact[n] * invfact[r] * invfact[n - r] % mod def bernoulli(n, mod): B = [0] * (n + 1) B[0] = 1 B[1] = (- pow(2, mod - 2, mod)) % mod for i in range(2, n, 2): inv = invfact[i+1] * fact[i] B[i] -= inv * comb(i + 1, 1) * B[1] for k in range(0, i, 2): B[i] -= inv * comb(i + 1, k) * B[k] B[i] %= mod return B N, K = map(int, input().split()) ans = 0 v = pow(N + 1, K + 1, mod) inv = pow(N + 1, mod - 2, mod) B = bernoulli(K + 5, mod) v2 = fact[K + 1] for i in range(K + 1): ans += comb(K + 1, i) * B[i] * v v *= inv ans %= mod v %= mod ans *= pow(K + 1, mod - 2, mod) print(ans%mod)