#include using namespace std; const int MOD=10; int pw(int n,int k){ assert(k>=0); int res=1; while(k){ if(k&1)(res*=n)%=MOD; (n*=n)%=MOD; k>>=1; } return res; } signed main(){ string n,m;cin>>n>>m; int N=(int)(n.back()-'0'),M=(int)(m.back()-'0'); if(m.size()>=2)M+=10*(int)(m[m.size()-2]-'0'); M+=3; cout<<(pw(N,M+3)*N)%MOD<