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