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