package main import ( "fmt" "strconv" ) func mod4(s string) int { l := len(s) if l > 2 { s = s[l-2:] } x, _ := strconv.Atoi(s) return x % 4 } func main() { var N, M string fmt.Scan(&N, &M) n := int(N[len(N)-1] - '0') x := 1 for i := 0; i < mod4(M)+4; i++ { x *= n } if M == "0" { x = 1 } fmt.Println(x % 10) }