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