h=Hash.new 0;n,k=gets.split.map &:to_i;p *(0...n).map{|i|s,t,u=gets.split.map &:to_i;[-s,u,t,i]}.sort.map{|e|e[1]=h[e[1]]+=1;e}.sort.map(&:last)[0,k]