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