#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; signed main(){ string N,M; cin>>N>>M; reverse(N.begin(),N.end()); reverse(M.begin(),M.end()); vector latte; int c = 1; for(int i=0;;i++){ c *= (N[0]-'0'); c%=10; if(latte.size()!=0 && latte[0]==c) break; latte.push_back(c); } printf("%d\n",latte[(M[0]-'0'-1+latte.size())%latte.size()]); return 0; }