import std.array, std.stdio, std.string, std.algorithm, std.conv; void main() { char n = readln.strip[$]; string m = readln.strip[$-2 .. $]; int N = n.to!int; int M = m.to!int; if (M == 0) writeln(1); else { writeln(N ^^ ((M - 1) % 4 + 1) % 10); } }