n, k = map(int, input().split()) m = 10 ** 5 items = [[] for _ in range(m)] for i in range(n): si, pi, ui = map(int, input().split()) ui -= 1 items[ui].append((si, pi, i)) teams = [] for ui in range(m): items[ui].sort(key=lambda x: (- x[0], x[2])) for j in range(len(items[ui])): si, pi, i = items[ui][j] teams.append((- si, j, pi, i)) teams.sort() print(*[i for _, _, _, i in teams[:k]], sep="\n")