function Main(s) {
  var s = s.split("\n")[0].split(" ").map(e => e*1);
  ans = 1;
  for (var i = 0; i < s[0]; i++) {
    if(i === 0) {
      ans *= s[1]; 
    } else {
      ans *= (s[1] - 1) % 1000000007;
    }
  }
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));