import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines n, k=map(int, readline().split()) spu=list(map(int, read().split())) s=spu[::3] p=spu[1::3] u=spu[2::3] num=[0]*n v=[[] for _ in range(100001)] for i, x in enumerate(u): v[x].append(i) for x in range(100001): if v[x]: v[x].sort(key=lambda i: -s[i]*(10**7)+p[i]) for j, i in enumerate(v[x]): num[i]=j q=[(-s[i], num[i], p[i], i) for i in range(n)] q.sort() for i in range(k): print(q[i][3])