import copy P,K=map(int,input().split()) now=[0,0] pnow=[1,0] d=1000000007 for i in range(K): now=[0,0] now[0]+=pnow[0]*(P+1) now[0]+=pnow[1]*2 now[1]+=pnow[0]*(P-1) now[1]+=pnow[1]*(P-2)*2 now[0]%=d now[1]%=d pnow=copy.deepcopy(now) print(now[0])