frc = [4, 2, 8, 5, 7, 1] N = int(raw_input()) print frc(N%6)