input = STDIN.readline.split()
n = input[0].to_i
k = input[1].to_i
td_list = STDIN.readlines
td_list.map!{|line|line.split()}
hash_list = []
for td in td_list do
    t = td[0]
    d = td[1].to_i
    hash_list.push(Hash[:t, t, :d, d])
end
hash_list.sort! do |a, b|
    a[:d] <=> b[:d]
end
hash_list.reverse!
answer = hash_list[Range.new(0, k, true)]
counter = Hash.new(0)
for td_a in answer do
    counter[td_a[:t]] += 1
end
once = answer.select do |once_td|
    counter[once_td[:t]] == 1
end
twice = answer.select do |twice_td|
    counter[twice_td[:t]] > 1
end
twice.reverse!