from operator import itemgetter N,K = map(int,input().split()) team = [() for i in range(N)] for i in range(N): s,p,u = map(int,input().split()) team[i] = (s,p,u,i) team = sorted(team,key=itemgetter(2)) team = sorted(team,key=itemgetter(0),reverse=True) cnt = [0 for i in range(100000 + 1)] for i in range(N): cnt[team[i][2]]+=1 team[i] = (team[i][0],team[i][1],team[i][2],team[i][3],cnt[team[i][2]]) team = sorted(team,key=itemgetter(2)) team = sorted(team,key=itemgetter(4)) team = sorted(team,key=itemgetter(0),reverse=True) for i in range(K): print(team[i][3])