P,K=map(int,input().split()) Mod=10**9+7 p_pow=1 x=1 for _ in range(1,K+1): x=(p_pow+P*x+(p_pow-x))%Mod p_pow*=2*P p_pow%=Mod print(x)