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