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