import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String NSt = sc.next(); String MSt = sc.next(); int ans = pow(NSt,MSt); System.out.println(ans); } static int pow(String A, String B){ if(B.equals("0")){ return 1; } int x = A.length(); int N = Integer.parseInt(A.substring(x-1)); int y = B.length(); if(y<3){y=3;} int M = Integer.parseInt(B.substring(y-3)); int r = M%4; int z = N; if(r==0){ z = (int)(Math.pow(N,4))%10; }else if(r!=1){ z = (int)(Math.pow(N,r))%10; } return z; } }