import java.util.*; import java.lang.*; import java.math.*; public class Main { void run() { Scanner sc = new Scanner(System.in); BigInteger N = sc.nextBigInteger(); BigInteger M = sc.nextBigInteger(); System.out.println(N.modPow(M, BigInteger.TEN)); } public static void main(String[] args) { new Main().run(); } }