import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void main() { string n; readV(n); string m; readV(m); if (m == "0") { writeln(1); return; } auto n1 = n[$-1..$].to!int; auto m2 = m[$-min(m.length, 2)..$].to!int; writeln(n1^^((m2+3)%4+1) % 10); }