n = gets.chomp.to_i cycle = [2, 8, 5, 7, 1, 4] p cycle[n % cycle.size - 1]