n, k = map(int, input().split()) a = list(map(int, input().split())) state_map = {} history = [] current = a.copy() step = 0 state_map[tuple(current)] = step history.append(current.copy()) found_cycle = False while step < k: if step == k: break x = current[0] m = x + 1 if m > n: m = n rotated = current[1:m] + [current[0]] new_array = rotated + current[m:] current = new_array step += 1 current_tuple = tuple(current) if current_tuple in state_map: # Cycle detected prev_step = state_map[current_tuple] cycle_length = step - prev_step remaining = k - step remaining %= cycle_length for _ in range(remaining): x = current[0] m = x + 1 if m > n: m = n rotated = current[1:m] + [current[0]] new_array = rotated + current[m:] current = new_array found_cycle = True break else: state_map[current_tuple] = step history.append(current.copy()) if not found_cycle: current = history[-1] print(' '.join(map(str, current)))