N, K = map(int, input().split()) Teams = [] for i in range(N): S, P, U = map(int, input().split()) Teams.append([S, P, U, i, 0]) Teams.sort(key=lambda x: (-x[0], x[1])) Univ = [1] * (10 ** 5) for i in range(N): Teams[i][4] = Univ[Teams[i][2]] Univ[Teams[i][2]] += 1 Teams.sort(key=lambda x: (-x[0], x[4], x[1])) for i in range(K): print(Teams[i][3])