using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.Linq; class Magatro { static void Main() { string N = Console.ReadLine(); string M = Console.ReadLine(); char NLast = N[N.Length - 1]; char MLast = M[M.Length - 1]; switch (NLast) { case '0': case '1': case '5': case '6': Console.WriteLine(NLast); break; default: int n = int.Parse(NLast.ToString()); int m = mod(M, 4); Console.WriteLine(myPow(n, m)); break; } } static string myPow(int n,int m) { string s = Math.Pow(n, m).ToString(); return s[s.Length - 1].ToString(); } static int mod(string S,int M) { int N = int.Parse(S[S.Length - 2].ToString() + S[S.Length - 1]); if (M == 4) { return N % 4; } else { return -1; } } }