#include using namespace std; using ll = long long; using P = pair; using T = tuple; #define al(a) a.begin(), a.end() #define ral(a) a.rbegin(), a.rend() #define sz(a) (int)a.size() #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define db(a, b) cout << #a << ": " << a << " " << #b << ": " << b << endl; int main() { string s, t; cin >> s >> t; if (t == "0") { cout << 1 << endl; return 0; } int n = s.back() - '0'; int m = 0; if (sz(t) == 1) m = t[0] - '0'; else { m = stoi(t.substr(sz(t) - 2)); } m %= 4; int ans = int(pow(n, m)) % 10; // while (m) { // ans *= n; // ans %= 10; // m--; // } cout << ans << endl; return 0; }