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())); b %= 4; b += 4; } else { b = Integer.parseInt(mString); if (b != 0) { b %= 4; b += 4; } } System.out.println((int) (Math.pow(a, b) % 10)); } }