#include using namespace std; int main() { #define DEBUG #ifdef DEBUG std::ifstream in("/home/share/inputf.in"); std::cin.rdbuf(in.rdbuf()); #endif string N, M; cin >> N >> M; int n = N.back() - 0x30; int m = stoi(M.substr(max(M.length() - 2, 0))); if(m != 0) m = (m % 4) + 4; int ans = (int)pow(n, m) % 10; cout << ans << endl; return 0; }