<끄적이면서 문제 이해해봄>
import java.util.Scanner;
public class 해시해킹26008 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int M = sc.nextInt();
int A = sc.nextInt();
int h = sc.nextInt();
long answer = 1;
for (int i = 0; i < N - 1; i++) {
answer = (answer * M) % 1000000007;
}
System.out.println(answer);
}
}
import java.io.*;
import java.util.StringTokenizer;
public class 해시해킹_1 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer stkr = new StringTokenizer(br.readLine());
long n = Integer.parseInt(stkr.nextToken());
long a = Integer.parseInt(stkr.nextToken());
long m = Integer.parseInt(stkr.nextToken());
long h = Integer.parseInt(br.readLine());
long answer = 1;
for (int i = 0; i < n - 1; i++) {
answer = (answer * m) % 1000000007;
}
bw.write(String.valueOf(answer));
bw.close();
bw.flush();
}
}