m=10**9+7;n,k=map(int,input().split());print((pow(n,k,m)-pow(n-1,k,m))*n%m)