import sys sys.set_int_max_str_digits(10 ** 6) input = sys.stdin.buffer.readline print('428571'[pow(int(input()), int(input()), 6)])