from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline P,K = map(int,input().split()) mod = 10**9 + 7 a = [0]*(K+1) b = [0]*(K+1) a[0] = 1 for i in range(K): a[i+1] = (P+1)*a[i]+2*b[i] a[i+1] %= mod b[i+1] = (P-1)*a[i]+2*(P-1)*b[i] b[i+1] %= mod print(a[-1])