def main(): mod = 10 ** 9 + 7 n, k = map(int, input().split()) ans = (n * (pow(n, k, mod) - pow(n - 1, k, mod))) % mod print(ans) if __name__ == "__main__": main()