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] v=list(range(n)) v.sort(key=lambda i: (-s[i], p[i])) c=[0]*n cu=[0]*100001 for i in v: c[i]=cu[u[i]] cu[u[i]]+=1 v.sort(key=lambda i: (-s[i], c[i], p[i])) print('\n'.join(map(str, v[:k])))