import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); char[] N = sc.next().toCharArray(); String mString = sc.next(); sc.close(); int a = Character.getNumericValue(N[N.length - 1]); int b = 0; if (mString.length() > 2) { b = Integer.parseInt(mString.substring(mString.length() - 2, mString.length())); } else { b = Integer.parseInt(mString); } b %= 4; System.out.println((int) (Math.pow(a, b) % 10)); } }