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