#include using lint=long long; using real=long double; int main(){ std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false); std::cout.setf(std::ios_base::fixed);std::cout.precision(15); std::string s,t;std::cin>>s>>t; lint a=std::accumulate(s.begin(),s.end(),0ll,[](lint cum,char c){return cum+c-'0';})%3; lint b=(s.back()-'0')%2; lint n=0; for(;n<6;n++){ if(n%3==a&&n%2==b)break; } assert(0<=n&&n<6); if((t.back()-'0')%2==0){ if(n==2)n=4; if(n==5)n=1; } std::cout<<"428571"[n]<<'\n'; } /* * 0 * 1 * 2 4 * 3 * 4 * 5 1 */