A,N = map(int,input().split()) M = 10**7 def pow_r(x, n): if n == 0: return 1 if n % 2 == 0: return pow_r(x ** 2, n // 2)%M else: # standard case ② n is odd return x * pow_r(x ** 2, (n - 1) // 2)%M print(pow_r(A,N))