from sys import stdin def main(): N = int(input()) num = [0, 2, 8, 5, 7, 1, 4] n = N % 6 print(num[n]) input = lambda: stdin.readline() main()