using System; using System.Linq; using System.Collections.Generic; class Program { static void Main() { var N = rs(); var M = rs(); var n = int.Parse(N[N.Length - 1].ToString()); int m; if (M.Length == 1) m = int.Parse(M); else m = int.Parse(M[M.Length - 2].ToString() + M[M.Length - 1]); if (m == 0 && M.Length == 1) { Console.WriteLine(1); return; } m %= 4; if (m == 0) m += 4; Console.WriteLine(Math.Pow(n, m) % 10); } #region Scan static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static string rs() { return Console.ReadLine(); } static int[] ria() { return Console.ReadLine().Trim().Split().Select(int.Parse).ToArray(); } static long[] rla() { return Console.ReadLine().Trim().Split().Select(long.Parse).ToArray(); } static double[] rda() { return Console.ReadLine().Trim().Split().Select(double.Parse).ToArray(); } static string[] rsa() { return Console.ReadLine().Trim().Split(); } static void mul(out int a, out int b) { var arr = ria(); a = arr[0]; b = arr[1]; } public void mul(out int a, out int b, out int c) { var arr = ria(); a = arr[0]; b = arr[1]; c = arr[2]; } public void mul(out int a, out int b, out int c, out int d) { var arr = ria(); a = arr[0]; b = arr[1]; c = arr[2]; d = arr[3]; } #endregion }