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