#include using namespace std; using ll = long long; constexpr long long MOD = 1000000007; int main(){ ll p, k; cin >> p >> k; ll dp[k + 1]; for (ll i = 0; i < k + 1; i++) dp[i] = 0; dp[0] = 1; for (ll i = 0; i < k; i++) { dp[i + 1] += dp[i] * p; dp[i + 1] += dp[i]; dp[i + 1] %= MOD; } cout << dp[k] << endl; }