# Read the input n = int(input()) # Define the sequence based on the derived formula sequence = [7, 4, 1, 8, 5, 2, 9, 6, 3, 0] # Output the nth element (adjusting for 0-based index) print(sequence[n-1])