# https://codeforces.com/contest/622/problem/F n,K=map(int,input().split()) mod=10**9+7 FACT=[1]*(10+10**6) F=[0]*(10+10**6) for i in range(1,10+10**6): FACT[i]=FACT[i-1]*i%mod F[i]=(F[i-1]+pow(i,K,mod))%mod FACT_INV=[0]*(10+10**6) FACT_INV[-1]=pow(FACT[-1],mod-2,mod) for i in range(10+10**6-1,0,-1): FACT_INV[i-1]=FACT_INV[i]*i%mod T=K+2 def powKsum(x): if x<=T: return F[x] ANS=0 PI=1 for i in range(1,K+3): PI=PI*(x-i)%mod if (T-i)%2==0: ANS+=F[i]*FACT_INV[T-i]*FACT_INV[i-1]*pow(x-i,mod-2,mod) else: ANS-=F[i]*FACT_INV[T-i]*FACT_INV[i-1]*pow(x-i,mod-2,mod) ANS%=mod return ANS*PI%mod print(powKsum(n))