#include using namespace std; int main(){ string n,m;cin>>n>>m; if(m == "0"){ cout << 0 << endl; return 0; } int N = n[n.size()-1]-'0'; int M; if(m.size() == 1){ M = m[0]-'0'; }else{ M = (m[m.size()-2]-'0')*10 + m[m.size()-1]-'0'; } M %= 4; int ans = N; for(int i = 0; M > i; i++){ ans = (N*ans)%10; } cout << ans << endl; }