n = int(input()) l = [2,8,5,7,1,4] if n > 6: print(l[n%6-1]) else: print(l[n-1])