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 m = 4; } else { int ans = n; for (int i = 1; i < m; i++) ans = (ans * n) % 10; System.out.println(ans); } } }