numList = ["2", "8", "5", "7", "1", "4"] n = int(input()) while n >= 6: n = n - 6 else: print(numList[n - 1])