#include #include #include #include #include #include #include #include #include #include using ll = long long; using namespace std; int div(string s, int div){ int i; i = stoi(s.substr(0, 1)); s = s.substr(1); while (s.size()){ i *= 10; i += stoi(s.substr(0, 1)); s = s.substr(1); i %= div; } return i; } int main(){ string n, m; cin >> n >> m; int t1 = n[n.size()-1] - '0'; ll r, ans = t1; vector modulo{1, 1, 4, 4, 2, 1, 1, 4, 4, 2}; if (modulo[t1] == 1) { cout << n[n.size()-1] << endl; return 0; } else { r = div(m, modulo[t1]); while(--r){ ans *= t1; ans %= 10; } cout << ans << endl; } }