P,K=map(int,input().split()) Mod=10**9+7 A=2*pow(2*P,K,Mod)+pow(P-1,K+1,Mod) print((A*pow(P+1,Mod-2,Mod))%Mod)