import std.array, std.stdio, std.string, std.algorithm, std.conv; import std.bigint; void main() { BigInt N = readln.strip().to!BigInt; BigInt M = readln.strip().to!BigInt; if (M == 0) writeln(1); else { writeln(N ^^ ((M - 1) % 4 + 1) % 10); } }