#include using namespace std; int main() { string n, m; cin >> n >> m; int n2 = n[n.size() - 1] - '0'; int m2 = m[m.size()-1] - '0'; if(m.size()>1){ m2 += (m[m.size() - 2] - '0') * 10; } if (m2 == 0) { cout << 1 << endl; } else { m2 = (m2 % 4 == 0) ? 4 : m2 % 4; cout << (int)pow(n2, m2) % 10 << endl; } return 0; }