#include #define rep(i,n) for(int i=(0);i<(n);i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll MOD = 1e9 + 7; ll p, k; cin >> p >> k; ll a = 1, b = 0; rep(i, k){ ll t = a; a = (p + 1) * a % MOD + 2 * (p - 1) * b % MOD; a %= MOD; b = t + 2 * (p - 1) * b % MOD; b %= MOD; } cout << a << endl; }