#include<iostream>
#include<algorithm>
using namespace std;

int n,m;
struct grad{ int st[200005],sz; }c[10];

void add(grad &c,int w)
{
   int i=c.sz,swp;

   c.st[c.sz++]=w;

   while(i>0 && c.st[i]<c.st[i-1])
   {
      swp=c.st[i-1];
      c.st[i-1]=c.st[i];
      c.st[i]=swp;
      i--;
   }
}

void input()
{
   int i,j,type,t,w;
   int maxw,chosen;

   cin>>n>>m;

   for(i=0;i<n;i++)
   {
      cin>>type;

      if(type==1)
      {
         cin>>t>>w;
         add(c[t],w);

         /*for(i=1;i<=m;i++)
         {
            cout<<"      grad "<<i<<"   ";
            for(j=0;j<c[i].sz;j++)
               cout<<c[i].st[j]<<' ';
            cout<<endl;
         }*/
      }

      else
      {
         maxw=0;
         for(j=1;j<=m;j++)
            if(c[j].st[0]>maxw)
            {
               maxw=c[j].st[0];
               chosen=j;
            }

         /*for(i=1;i<=m;i++)
         {
            cout<<"      grad "<<i<<"   ";
            for(j=0;j<c[i].sz;j++)
               cout<<c[i].st[j]<<' ';
            cout<<endl;
         }*/

         cout<</*"      out: "<<*/c[chosen].st[0]<<endl;
         for(j=0;j<c[chosen].sz-1;j++)
            c[chosen].st[j]=c[chosen].st[j+1];
         c[chosen].sz--;

      }
   }
}

int main()
{
   input();

   return 0;
}

/*
9 2
1 1 9
1 2 3
1 1 4
2
1 1 2
1 2 5
2
2
1 2 1

=>
4
3
5
*/
