x = int(input())p = int(input())print((x%10) ** (1+(p+3)%4) % 10 if p else 1)
2 4
6
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!