#include #include using namespace std; int main(){ string N; cin >> N; string M; cin >> M; if (M == "0"){ cout << 1 << endl; return 0; } M = "0" + M; int a = stoi(N.substr(N.size() - 1)); int b = stoi(M.substr(M.size() - 2)) % 4 + 4; int ans = 1; for (int i = 0; i < b; i++){ ans *= a; } cout << ans % 10 << endl; }