import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) sys.setrecursionlimit(10**7) yes = lambda :print("yes");Yes = lambda :print("Yes") no = lambda :print("no");No = lambda :print("No") ####################################################################### n,k = na() mod = 10**9+7 print(n*(pow(n,k,mod)-pow(n-1,k,mod))%mod)