import java.util.*; public class Main { static final int MOD = 1000000007; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int p = sc.nextInt(); int k = sc.nextInt(); long prevZero = 1; long prevNotZero = 0; for (int i = 0; i < k; i++) { long nextZero = (prevZero * (p + 1) + prevNotZero * 2) % MOD;; long nextNotZero = (prevZero * (p - 1) + prevNotZero * (2 * p - 2)) % MOD; prevZero = nextZero; prevNotZero = nextNotZero; } System.out.println(prevZero); } }