package main import ( "fmt" "math" ) func main() { var n, m string _, _ = fmt.Scan(&n, &m) fmt.Println(int(math.Pow(float64(n[len(n)-1]-'0'), float64(m[len(m)-1]-'0'))) % 10) }