#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define MAX_MOD 1000000007 #define REP(i,n) for(long long i = 0;i < n;++i) #define LONG_INF 100000000000000 int main() { string a, b; cin >> a >> b; long long left = a[a.length() - 1] - '0'; long long right = b[b.length() - 1] - '0'; if (b.length() != 1) { right += (b[b.length() - 2] - '0') * 10; if (b.length() != 2) right += (b[b.length() - 3] - '0') * 100; } long long ans = 1; for (int i = 0;i < right % 4;++i) { ans *= left; } cout << ans % 10 << endl; return 0; }