import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String nString = sc.next(); String mString = sc.next(); sc.close(); int a = Character.getNumericValue(nString.charAt(nString.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)); } }