import java.math.BigInteger;
import java.util.Scanner;
public class P2574 {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
while (cin.hasNext()) {
BigInteger a = cin.nextBigInteger();
BigInteger b = cin.nextBigInteger();
BigInteger c = BigInteger.valueOf(10);
System.out.println(a.pow(b.intValue()).remainder(c));
}
}
}
import java.util.Scanner;
public class P2574 {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
while (cin.hasNext()) {
BigInteger a = cin.nextBigInteger();
BigInteger b = cin.nextBigInteger();
BigInteger c = BigInteger.valueOf(10);
System.out.println(a.pow(b.intValue()).remainder(c));
}
}
}