n, k = map(int, input().split()) a = list(map(int, input().split())) current = a.copy() seen = {} history = [current.copy()] for step in range(k): current_tuple = tuple(current) if current_tuple in seen: start_step = seen[current_tuple] cycle_length = step - start_step remaining_steps = k - step if remaining_steps > 0: pos_in_cycle = remaining_steps % cycle_length current = history[start_step + pos_in_cycle] else: current = history[step] break seen[current_tuple] = step x = current[0] m = x + 1 if m > n: m = n current = current[1:m] + [current[0]] + current[m:] history.append(current.copy()) else: current = history[-1] print(' '.join(map(str, current)))