#include #include #include using namespace std; int main(){ int n,m; string a,b; cin >> a >> b; n = (a[a.size() - 2] - '0') * 10 + (a.back() - '0'); m = (b[b.size() - 2] - '0') * 10 + (b.back() - '0'); if(m == 0){ cout << 1 << endl; return 0; } n %= 10; m %= 4; if(!m) m = 4; cout << int(pow(n,m)) % 10 << endl; }