import java.util.*; import java.io.*; import java.math.BigInteger; import static java.util.Arrays.*; import static java.lang.Math.*; public class No167 { static final InputStream in = System.in; static final PrintWriter out = new PrintWriter(System.out,false); static void solve() throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BigInteger n = new BigInteger(br.readLine()); BigInteger m = new BigInteger(br.readLine()); out.println(n.modPow(m,BigInteger.TEN)); } public static void main(String[] args) throws Exception { long start = System.currentTimeMillis(); solve(); out.flush(); long end = System.currentTimeMillis(); //trace(end-start + "ms"); in.close(); } static void trace(Object... o) { System.out.println(deepToString(o));} }