n = int(input()) result = 0 if n%6 == 0: result = 4 elif n%6 == 1: result = 1 elif n%6 == 2: result = 7 elif n%6 == 3: result = 5 elif n%6 == 4: result = 8 elif n%6 == 5: result = 2 print(result)