import scala.io.StdIn object Problem167 { def proc(N: String, M: String): Int = { if (M.length == 1 && M.toInt == 0) return 1 val a = N.last.asDigit val b = M.takeRight(2).toInt % 4 match { case 0 => 4 case x => x } Math.pow(a, b).toInt % 10 } def main(args: Array[String]) = { val N = StdIn.readLine() val M = StdIn.readLine() val result: Int = proc(N, M) println(result) } }