#include #include #include #include #include #include #include #include using ll = long long; using namespace std; int main(void) { string s, t; cin >> s >> t; int n = s.size(); int m = t.size(); int tmp = s[n - 1] - '0'; int num = (t[m - 2] - '0') * 10 + (t[m - 1] - '0'); num %= 4; //cout << tmp << " " << num << endl; int ababa = (int)pow(tmp, num) % 10; cout << ababa << endl; return 0; }