//#include #include #include using namespace std; //using namespace atcoder; using ll = long long; #define all(A) A.begin(),A.end() using vll = vector; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) using Graph = vector>; int main() { string S="285714"; string N; cin>>N; bool T=((N[N.size()-1]-'0')%2==0); ll Th=0; rep(i,N.size()){ Th+=N[i]-'0'; Th%=3; } string K; cin>>K; K="0"+K; ll f=(K[K.size()-2]-'0')*10+K[K.size()-1]-'0'; f%=4; if(f==0)f+=4; ll s=0; if(T){ if(Th==0){ s=0; } else if(Th==1){ s=4; } else{ s=2; } } else{ if(Th==0){ s=3; } else if(Th==1){ s=1; } else{ s=5; } } //cout<