N, K = tuple(int(i) for i in input().split()) team_lst = [] school_dic = {} for i in range(N): sn, pn, un = tuple(int(i) for i in input().split()) team_lst += [(sn, -pn, un, i)] team_lst = sorted(team_lst, reverse=True) team_lst2 = [] for r in team_lst: sn, pn, un, idx = r sum_un = school_dic.get(un, 0) + 1 school_dic[un] = sum_un team_lst2 += [(sn, -sum_un, pn, idx)] team_lst2 = sorted(team_lst2, reverse=True) for r in team_lst2[:K]: _, _, _, idx = r print(r[3])