N, K = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)

0.upto(N - 2) do |i|
  if A[i] == A[i + 1]
    A[i] = A[i + 1] = nil
  end
end

A.compact!

if A.empty?
  puts ''
  exit
end

pos = Hash.new { |h, k| h[k] = [] }
edges = Hash.new
edges[0] = A.first

A.each_with_index do |a, i|
  pos[a] << i
end

pos.each do |a, list|
  if list.size == 1
    edges[a] = A[list.first + 1] || 0
  else
    edges[a] = A[list[1] + 1] || 0
  end
end

v = 0
l = 0

path = [0]

(K - 1).times do
  v = edges[v]

  break if v == 0

  path << v
end

l = path.size
v = path[(K - 1) % l]
stack = if v == 0
          []
        else
          [v]
        end
counter = Hash.new(0)
counter[v] += 1

A.each do |a|
  if counter[a] > 0
    while counter[a] > 0
      counter[stack.pop] -= 1
    end
  else
    stack << a
    counter[a] += 1
  end
end

puts stack.join(' ')
