import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Scanner; /** * Built using CHelper plug-in * Actual solution is at the top * * @author silviase */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); No1049ZeroExhaust solver = new No1049ZeroExhaust(); solver.solve(1, in, out); out.close(); } static class No1049ZeroExhaust { public void solve(int testNumber, Scanner in, PrintWriter out) { int p = in.nextInt(); int k = in.nextInt(); ModInt[] z = new ModInt[k + 1]; ModInt[] nz = new ModInt[k + 1]; z[0] = new ModInt(1); nz[0] = new ModInt(0); for (int i = 0; i < k; i++) { z[i + 1] = z[i].mul(p + 1).add(nz[i].mul(2)); nz[i + 1] = z[i].mul(p - 1).add(nz[i].mul(2 * p - 2)); } out.println(z[k].getVal()); } } static class ModInt { public long val; final int MOD = (int) 1e9 + 7; public ModInt(long i) { this.val = (i + MOD) % MOD; } public ModInt mul(long l) { return new ModInt(this.val * l); } public ModInt add(ModInt m) { return new ModInt(this.val + m.val); } public long getVal() { return val; } public String toString() { return Long.toString(val); } } }