/*
#include <stdio.h>
struct student
{
int score, grade;
};
int main()
{
struct student st[200];
int i,sum=1,j,n;
scanf("%d",&n);
for(i=1; i<=n; i++)
{
scanf("%d",&st[i].score);
}
for(i=1; i<=n; i++)
{
for(j=1; j<=n; j++)
{
if(st[i].score<st[j].score)
{
sum++;
}
}
st[i].grade=sum;
printf("%d %d\n",st[i].score,st[i].grade);
sum=1;
}
return 0;
}
*/
/*
#include <stdio.h>
struct student
{
int country,number,score;
};
int main()
{
struct student st[101];
int i,j,n,c[3],max=1;
scanf("%d",&n);
for(i=1; i<=n; i++)
{
scanf("%d %d %d",&st[i].country,&st[i].number,&st[i].score);
}
for(i=1; i<=3; i++)
{
max=1;
for(j=1; j<=n; j++)
{
if(st[max].score<st[j].score)
{
max=j;
}
}
c[i]=st[max].country;
printf("%d %d\n",st[max].country,st[max].number);
st[max].score=0;
if(i==2 && c[1]==c[2])
{
for(j=1; j<=n; j++)
{
if(st[j].country==c[1])
{
st[j].score=0;
}
}
}
}
return 0;
}
*/
#include<stdio.h>
struct student
{
char name[11];
int score;
};
int main()
{
struct student st[101],temp;
int i,j,n,m;
scanf("%d %d",&n,&m);
for(i=1; i<=n; i++)
{
scanf("%s %d",&st[i].name,&st[i].score);
}
for(i=1; i<n; i++)
{
for(j=1; j<=n-i; j++)
{
if(st[j].score<st[j+1].score)
{
temp=st[j];
st[j]=st[j+1];
st[j+1]=temp;
}
}
}
for(i=1; i<=m; i++)
{
printf("%s\n",st[i].name);
}
}