n = int(input()) num_arr = [4, 2, 8, 5, 7, 1] res = num_arr[n % 6] print(res)