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 ns; readV(ns); string ks; readV(ks); auto n = ns.map!(c => cast(int)(c-'0')).array; auto k = ks.map!(c => cast(int)(c-'0')).array; auto nm2 = n[$-1]%2, nm3 = n.sum%3, km2 = k[$-1]%2; auto nm6 = [[0,4,2],[3,1,5]][nm2][nm3]; auto nkm6 = [[0,1,4,3,4,1],[0,1,2,3,4,5]][km2][nm6]; writeln("428571"[nkm6]); }