#include <bits/stdc++.h>
using namespace std;
map<int,int>p;
struct st
{
int num;
int period;
bool operator <(const st other) const
{
if(period!=other.period)
return period>other.period;
else
return num>other.num;
}
};
priority_queue<st>v;
int main()
{
int n,k;
cin>>n>>k;
for(int i=0; i<n; i++)
{
string s;
int num,period;
cin>>s>>num>>period;
st a;
a.num=num;
a.period=period;
v.push(a);
p[num]=period;
}
for(int i=0; i<k; i++)
{
st a=v.top();
v.pop();
printf("%d\n",a.num);
a.period+=p[a.num];
v.push(a);
}
return 0;
}