mod = 10 ** 9 + 7 n, k = map(int, input().split()) print((pow(n, k, mod) - pow(n - 1, k, mod)) * n % mod)