#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 = 10 + m; int n = (int)(N[N.length() - 1] - '0'); res = n; for (int i = 1; i < m % period[n]; ++i){ res = (res * n) % 10; } // end for } // end if cout << res << endl; return 0; }