
import java.io.*;
import java.lang.*;
import java.util.*;

public class A1239 {
    public static void main(String[] args) throws IOException{
        StringTokenizer st;
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        st = new StringTokenizer(f.readLine());
        int r = Integer.parseInt(st.nextToken());
        int x = Integer.parseInt(st.nextToken());
        f.close();
        int m = Math.max(r,x);
        int n = Math.min(r,x);
        long op = n;
        long MOD = 1000000007;
        for(int i = 0; i < m-1; i++){
            op*=n;
            op%=MOD;
        }



        System.out.println(op);
    }

}