import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) { BufferedReader stdReader =new BufferedReader(new InputStreamReader(System.in)); try { int x = Integer.parseInt(stdReader.readLine()); int N = Integer.parseInt(stdReader.readLine()); int ans = pow(x, N,10) % 10; System.out.println(ans); } catch (IOException e) { e.printStackTrace(); } } public static int pow(int x,int n,int m){ long temp = x; long ans = 1; while(n>0){ if(n%2==0){ temp = temp*temp % m; n /= 2; }else{ n -= 1; ans = ans *temp % m; } } return (int)ans; } }