import std; void main() { auto N = readln.chomp; auto M = readln.chomp; if (M == "0") { 1.writeln; return; } int res = N[$-1] - '0'; if (res.among(0, 1, 5, 6)) { res.writeln; return; } int p = M[$-1] - '0'; if (M.length > 1) { p += (M[$-2] - '0') * 10; } p %= 4; foreach (i; 2 .. p+1) { res = (res * res) % 10; } res.writeln; }