#include #include #include using namespace std; using ll = long long; int main() { string n, m; cin >> n >> m; if (m == "0")cout << 1 << endl; else { int x = n.back() - '0'; int y = 0; for (int i = 0; i < m.size(); i++) { y *= 10, y %= 3628800; y += m[i] - '0', y %= 3628800; } if (y == 0)y = 3628800; int ret = 1; for (int i = 0; i < y; i++) { ret *= x, ret %= 10; } cout << ret << endl; } return 0; }