#include #include int main(void) { int i, j; char n[10001], m[10001]; int n2, m2; scanf("%s", n); scanf("%s", m); m2 = m[0] - '0'; i = 1; while(m[i] != '\0'){ m2 = m2 * 10 + m[i] - '0'; m2 %= 4; i++; } //printf("%d\n", m2); if(i == 1 && m2 == 0){ printf("1\n"); return 0; } j = 0; while(n[j] != '\0'){ j++; } n2 = n[j - 1] - '0'; if(n2 == 1 || n2 == 5 || n2 == 6){ printf("%d\n", n2); return 0; } //printf("%d^%d = %d\n", n2, m2, (int)pow(n2, m2) % 10); printf("%d\n", (int)pow(n2, m2 + 4) % 10); return 0; }