#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define fix(n) cout<; const ll MOD = 1000000007; // 10^9 + 7 const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; void solve() { string N, M; cin >> N >> M; if (M == "0") { outl(1); return; } ll n = N[N.size()-1] - '0'; ll m; if (M.size() < 2) m = stoll(M); else m = stoll(M.substr(M.size()-2)); if (n == 0 || n == 1 || n == 5 || n == 6) outl(n); else if (n == 4) outl(m % 2 == 1 ? 4 : 6); else if (n == 9) outl(m % 2 == 1 ? 9 : 1); else { m %= 4; map> map; map[2] = {6, 2, 4, 8}; map[3] = {1, 3, 9, 7}; map[7] = {1, 7, 9, 3}; map[8] = {6, 8, 4, 2}; outl(map[n][m]); } } signed main() { cin.tie(0); ios::sync_with_stdio(false); srand((unsigned)time(NULL)); fix(12); solve(); }