import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; public class Main { public static void main(String[] args) { BufferedReader stdReader =new BufferedReader(new InputStreamReader(System.in)); try { BigInteger n = new BigInteger(stdReader.readLine()); BigInteger m = new BigInteger(stdReader.readLine()); System.out.println(n.modPow(m, BigInteger.valueOf(10))); } catch (IOException e) { e.printStackTrace(); } } }