MOD = 10**9 + 7 N, M = map(int, input().split()) print(pow(M, N, MOD))