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(); int N = Integer.parseInt(str); str = br.readLine(); int M = Integer.parseInt(str); if (M == 0) System.out.println("1"); else { int ans = N % 10; for (int i = 1; i < M; i++) ans = (ans * N) % 10; System.out.println(ans); } } }