P = 1000000007 n, k = map(int,input().split()) ans = n * (pow(n, k, P) - pow(n, k-1, P)) % P print(ans)