import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str = br.readLine(); String[] N = str.split(""); int n = Integer.parseInt(N[N.length - 1]); str = br.readLine(); String[] M = str.split(""); int m = 0; if (M.length == 1) m = Integer.parseInt(M[0]); else { m = Integer.parseInt(M[M.length - 2]) * 10 + Integer.parseInt(M[M.length - 1]); } if (m == 0) { if (M.length == 1) System.out.println("1"); else System.out.println((int) Math.pow(n, 4) % 10); } else { System.out.println((int) Math.pow(n, m % 4 + 4) % 10); } } }