n, k = map(int, input().split()) a = list(map(int, input().split())) if k == 0: print(' '.join(map(str, a))) exit() memo = {} current = tuple(a) memo[current] = 0 steps = 0 history = [a.copy()] cycle_found = False while steps < k: x = current[0] m = x + 1 new_list = list(current)[1:m] + [current[0]] + list(current)[m:] steps += 1 new_tuple = tuple(new_list) if new_tuple in memo: prev_step = memo[new_tuple] cycle_length = steps - prev_step remaining = (k - steps) % cycle_length for _ in range(remaining): x = new_list[0] m = x + 1 new_list = new_list[1:m] + [new_list[0]] + new_list[m:] print(' '.join(map(str, new_list))) cycle_found = True break else: memo[new_tuple] = steps current = new_tuple history.append(new_list) if not cycle_found: print(' '.join(map(str, current)))