#include #include #include #include #include #include #include using namespace std; int main() { string str_n, str_m; cin >> str_n >> str_m; int base = str_n[str_n.size() - 1] - '0'; if (str_m == "0") { cout << 1 << endl; return 0; } str_m = "0" + str_m; int len = str_m.size(); int multiple = (str_m[len - 2] - '0') * 10 + str_m[len - 1] - '0'; multiple %= 4; if (multiple == 0) { multiple = 4; } int ans = (int) pow(base, multiple) % 10; cout << ans << endl; return 0; }