n, k = map(int, input().split()) a = list(map(int, input().split())) if k == 0: print(' '.join(map(str, a))) exit() history = {} current = a.copy() steps = 0 found_cycle = False while steps < k: key = tuple(current) if key in history: prev_step = history[key] cycle_length = steps - prev_step remaining = k - steps remaining %= cycle_length k = remaining found_cycle = True break else: history[key] = steps a0 = current[0] m = a0 + 1 if m > len(current): m = len(current) new_current = current[1:m] + [current[0]] + current[m:] current = new_current steps += 1 if found_cycle: for _ in range(k): a0 = current[0] m = a0 + 1 if m > len(current): m = len(current) new_current = current[1:m] + [current[0]] + current[m:] current = new_current print(' '.join(map(str, current)))