#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair i_i; typedef pair ll_i; typedef pair d_i; typedef pair ll_ll; typedef pair d_d; struct edge { int u, v; ll w; }; ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-10; int main() { string N, M; cin >> N >> M; if (M == "0") { cout << 1 << endl; return 0; } reverse(N.begin(), N.end()); int x = N[0] - '0'; reverse(M.begin(), M.end()); M.push_back('0'); int y = (M[0] - '0') + (M[1] - '0') * 10 + 4; int z = 1; while (y--) z = z * x % 10; cout << z << endl; }