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