n = int(input()) m = int(input()) print(pow(n , m, 10))