import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String N = scan.next(); String M = scan.next(); scan.close(); if(M.equals("0")) { System.out.println(1); System.exit(0); } int n = Integer.parseInt(N.substring(N.length() - 1, N.length())); int m = 0; if(M.length() < 2) { m = Integer.parseInt(M); }else { m = Integer.parseInt(M.substring(M.length() - 2, M.length())); } m = m % 4; System.out.println((int)Math.pow(n, m + 4) % 10); } }