print((lambda n : x if 0 < (x := n%8) < 5 else (10-x)%8)(int(input())))