import java.util.Scanner

object Main extends App { 
  val sc = new Scanner(System.in)
  val N, K = sc.nextInt()
  val Base = 1000000007

  def expMod(base:Long, exponent:Long, mod:Long):Long = {
    require(base >= 0,     "Base must not be negative. Base="+base)
    require(exponent >= 0, "Exponent must not be negative. Exponent="+exponent)
    require(mod > 1, "Modulo must be grater than 1. Modulo="+mod)
    def iter(b:Long, e:Long, p:Long):Long = {
      (e, e & 1) match {
        case (0, _) => p
        case (_, 0) => iter((b*b) % mod, e >> 1, p % mod)
        case (_, _) => iter((b*b) % mod, e >> 1, (b*p) % mod)
      }
    }

    iter(base, exponent, 1)
  }

  println(expMod(K,N,Base))

}
