import java.math.BigInteger;
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
BigInteger a = in.nextBigInteger();
BigInteger b = in.nextBigInteger();
long c = in.nextLong();
long d = in.nextLong();
BigInteger r = in.nextBigInteger();
BigInteger m=a.multiply(b);
long n=c*d;
BigInteger t=m.modPow(BigInteger.valueOf(n), r);
System.out.println(t);
in.close();
}
}
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
BigInteger a = in.nextBigInteger();
BigInteger b = in.nextBigInteger();
long c = in.nextLong();
long d = in.nextLong();
BigInteger r = in.nextBigInteger();
BigInteger m=a.multiply(b);
long n=c*d;
BigInteger t=m.modPow(BigInteger.valueOf(n), r);
System.out.println(t);
in.close();
}
}