#include using namespace std; int main() { long long int N, M; cin >> N >> M; int p = N % 10; if (M == 0) { cout << 1; return 0; } long long int t = M; int k = p; int i = 0; do { k = (k * p) % 10; i++; } while (!(k == p)); t = M % i - 1 + i; for (int i = 0; i < t; i++) { int x = N % 10; p *= x; p = p % 10; } cout << p; getchar(); getchar(); return 0; }