#include #define rep(i,n) for(int i=0;i<(n);++i) #define ALL(A) A.begin(), A.end() using namespace std; typedef long long ll; typedef pair P; const int period[10] = { 1, 1, 4, 4, 2, 1, 1, 4, 4, 2 }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string N, M; cin >> N >> M; int res = 0; if (M.length() == 1 && M[0] == '0'){ res = 1; }else{ int m = (int)(M[M.length() - 1] - '0'); if (M.length() >= 2) m = (int)(M[M.length() - 2] - '0') * 10 + m; if (M.length() >= 3) m = 100 + m; int n = (int)(N[N.length() - 1] - '0'); res = n; // cerr << "n: " << n << " m: " << m << endl; for (int i = 1; i < m % (1 + period[n]); ++i){ res = (res * n) % 10; } // end for } // end if cout << res << endl; return 0; }