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(); if (marr.length == 1 && marr[0] == '0') { System.out.println(1); return; } int m = 0; for (int i = Math.max(0, marr.length - 3); i < marr.length; i++) { m *= 10; m += marr[i] - '0'; } if (m == 0) { m = 1000; } int ans = n; for (int i = 1; i < m; i++) { ans *= n; ans %= 10; } System.out.println(ans); } }