#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; long long mod = 1000000007; long long m_pow(long long x, long long y) { long long ans = 1; while (y > 0) { if ((y & 1) == 1) { ans = ans * x % mod; } x = x * x % mod; y >>= 1; } return ans; } int main() { long long n, k; cin >> n >> k; cout << (m_pow(n, k + 1) - (n * m_pow(n - 1, k) % mod) + mod) % mod << endl; }