#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() { ll N, M; cin >> N >> M; if (M == 0) { outl(1); return; } N %= 10; 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(); }