import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Iterator; public class Main_yukicoder167 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int MOD = 10; String n = sc.next(); String m = sc.next(); int nn = mod(n, MOD); if (m.equals("0")) { System.out.println("1"); } else { if (nn == 0) { System.out.println("0"); } else { int loop = mod(m, 4) - 1; if (loop < 0) { loop = 3; } int ret = nn; for (int i = 0; i < loop; i++) { ret *= nn; } System.out.println(ret % MOD); } } sc.close(); } private static int mod(String x, int MOD) { char[] xx = x.toCharArray(); long ret = 0; for (int i = 0; i < xx.length; i++) { ret *= 10; ret += xx[i] - '0'; ret %= MOD; } return (int)ret; } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { it = Arrays.asList(br.readLine().split(" ")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } }