import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); char[] narr = sc.next().toCharArray(); int n = narr[narr.length - 1] - '0'; char[] marr = sc.next().toCharArray(); int m = 0; for (int i = Math.max(0, marr.length - 3); i < marr.length; i++) { m *= 10; m += marr[i] - '0'; } int ans = n; for (int i = 1; i < m; i++) { ans *= n; ans %= 10; } System.out.println(ans); } }