import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long N = sc.nextLong(); long M = sc.nextLong(); long r = powmod(N,M); System.out.println(r); } static long powmod(long a, long b){ a%=10; long x=1; if(b==0){ return 1; }else if(b%2==0){ x = powmod(a*a%10, b/2)%10; }else{ x = a*powmod(a*a%10, b/2)%10; } return x; } }