#include using ll = long long; using namespace std; int main() { string n, m; int a, b, ans = 1; cin >> n >> m; a = n.back()- '0'; b = stoi(m.substr(m.size()-2,2)) % 4; for (int i = 0; i < b; ++i) { ans = (ans * a)%10; } cout << ans << "\n"; return 0; }