p,k=map(int,input().split()) mod=10**9+7 a,b=1,0 for i in range(k): a,b=((p+1)*a+2*(p-1)*b)%mod,(a+2*(p-1)*b)%mod print(a)