#include using namespace std; template T gcd(T x, T y) { if (y == 0) return x; return gcd(y, x % y); } template T lcm(T x, T y) { if (x == 0 || y == 0) return 0; return x / gcd(x, y) * y; } int main() { const int mod = 10; string N; cin >> N; string M; cin >> M; int m = stoi(M.size() > 3 ? M.substr(M.size() - 3) : M); if (m == 0) cout << 1 << endl; else { int n = N.back() - '0'; cout << (int)pow(n, (m + 3) % 4 + 1) % mod << endl; } }