#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); string N,M; cin >> N >> M; reverse(M.begin(), M.end()); while(M.size() > 2u) M.pop_back(); reverse(M.begin(), M.end()); int m4 = stoi(M) % 4; int n10 = N.back() - '0'; if(n10 == 0) { cout << 0 << endl; } else if(M == "0") { cout << 1 << endl; } else { cout << int(pow(n10, m4)) % 10 << endl; } }