#include using namespace std; template T gcd(T x, T y) { if (y == 0) return x; return gcd(y, x % y); } template T lcm(T x, T y) { if (x == 0 || y == 0) return 0; return x / gcd(x, y) * y; } int main() { string N; cin >> N; string M; cin >> M; const int mod = 10; int n = N[N.size() - 1] - '0'; int m = stoi(M.size() > 3 ? M.substr(M.size() - 3) : M); if (m == 0) { cout << 1 << endl; return 0; } int ans = 1; for (int i = 0; i < m; i++) { ans *= n; ans %= mod; } cout << ans << endl; }