n,k,*a=list(map(int,open(0).read().split()))

b=[[]for _ in range(max(a)+1)]

l=[]

for i,v in enumerate(a):

  b[v]+=i,

  l+=len(b[v]),

s=a[0]

i=c=0

while 1:

  t=b[s]

  m=len(t)

  j=l[i]

  c+=j==m

  i=t[j%m]+1

  if i==n:break

  s=a[i]

k%=c+1

s=a[0]

i=c=0

r=[]

while c<k-1or i<n:

  t=b[s]

  m=len(t)

  j=l[i]

  f=j==m

  if c>k-2and f:

    r+=s,

    i+=1

  else:i=t[j%m]+1

  c+=f

  s=a[i%n]

print((*r))
n,k,*a=list(map(int,open(0).read().split()))

b=[[]for _ in range(max(a)+1)]

l=[]

for i,v in enumerate(a):

  b[v]+=i,

  l+=len(b[v]),

s=a[0]

i=c=0

while 1:

  t=b[s]

  m=len(t)

  j=l[i]

  c+=j==m

  i=t[j%m]+1

  if i==n:break

  s=a[i]

k%=c+1

s=a[0]

i=c=0

r=[]

while 1:

  t=b[s]

  m=len(t)

  j=l[i]

  f=j==m

  if c>k-2and f:

    r+=s,

    i+=1

  else:i=t[j%m]+1

  c+=f

  if i==n:break

  s=a[i]

print((*r))
n, k, *a = list(map(int, open(0).read().split()))
b = [[] for _ in range(max(a) + 1)]
l = []
for i, v in enumerate(a):
    b[v] += (i,)
    l += (len(b[v]),)
s = a[0]
i = c = 0
while 1:
    t = b[s]
    m = len(t)
    j = l[i]
    c += j == m
    i = t[j % m] + 1
    if i == n:
        break
    s = a[i]
k %= c + 1
s = a[0]
i = c = 0
r = []
while c < k - 1 or i < n:
    t = b[s]
    m = len(t)
    j = l[i]
    f = j == m
    if c > k - 2 and f:
        r += (s,)
        i += 1
    else:
        i = t[j % m] + 1
    c += f
    s = a[i % n]
print((*r))

n, k, *a = list(map(int, open(0).read().split()))
b = [[] for _ in range(max(a) + 1)]
l = []
for i, v in enumerate(a):
    b[v] += (i,)
    l += (len(b[v]),)
s = a[0]
i = c = 0
while 1:
    t = b[s]
    m = len(t)
    j = l[i]
    c += j == m
    i = t[j % m] + 1
    if i == n:
        break
    s = a[i]
k %= c + 1
s = a[0]
i = c = 0
r = []
while 1:
    t = b[s]
    m = len(t)
    j = l[i]
    f = j == m
    if c > k - 2 and f:
        r += (s,)
        i += 1
    else:
        i = t[j % m] + 1
    c += f
    if i == n:
        break
    s = a[i]
print((*r))

-while c < k - 1 or i < n: +while 1: -    s = a[i % n] +    if i == n: +        break +    s = a[i]