#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
// ZA koito ne znae VednYj

long n,m,i,j,p;
long node,weight;

priority_queue<long> a[200000];

int main()
{cin>>n>>m;int max1=0,maxind;
for(i=0;i<n;i++)
{cin>>p;
if(p==2){max1=0;
for(int j=1;j<=m;j++)
{//cout<<a[i].top()<<' '<<i<<endl;
    //check(a[i]);
    if(fabs(a[j].top())>max1){max1=fabs(a[j].top());maxind=j;}
}

a[maxind].pop();
//check(a[maxind]);

cout<<max1<<endl;
}
else {cin>>node>>weight;
a[node].push(-weight);}

}

return 0;
}
