SIZE=10**5+1; MOD=10**9+7 #998244353 #ここを変更する inv = [0]*SIZE # inv[j] = j^{-1} mod MOD fac = [0]*SIZE # fac[j] = j! mod MOD finv = [0]*SIZE # finv[j] = (j!)^{-1} mod MOD fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 for i in range(2,SIZE): fac[i] = fac[i-1]*i%MOD finv[-1] = pow(fac[-1],MOD-2,MOD) for i in range(SIZE-1,0,-1): finv[i-1] = finv[i]*i%MOD inv[i] = finv[i]*fac[i-1]%MOD def Lagrange_interpolation(a,t): n = len(a)-1 t %= MOD if 0 <= t <= n: return a[t] rprod = [1]*(n+2) r = 1 for i in range(n+2): rprod[n+1-i] = r r = r*(t-n+i)%MOD ans, lprod = 0, 1 for i,ai in enumerate(a): bunsi = lprod*rprod[i+1]%MOD bunbo = finv[i]*finv[n-i]%MOD*(-1 if (n-i)%2 else 1) ans += bunsi*bunbo%MOD*ai%MOD lprod = lprod*(t-i)%MOD return ans%MOD n,k = map(int,input().split()) a = [pow(i,k,MOD) for i in range(2*k+4)] for i in range(1,2*k+4): a[i] += a[i-1] print(Lagrange_interpolation(a,n)%MOD)