MOD = 10 ** 9 + 7 N,K = map(int,input().split()) ans = (N * (pow(N,K,MOD) - pow(N-1,K,MOD))) % MOD print(ans)