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