#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<string.h>
#include<vector>
#include<queue>
#include<map>
using namespace std;
int n, m, t = 0, a[100][200001], ind[2000001], pr[2000001], h = 0, max1 = 0, indexes = 0, answer[2000001], g = 0;
map <int, int> towns;
void in()
{ scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++)
  { int t;
    scanf("%d", &t);
    if (t == 1)
    { int y, r;
      scanf("%d %d", &y, &r);
      a[y][ind[y]++] = r;
      sort(a[y], a[y] + ind[y]);
      towns[y] = y;
     }
    
    else
    { //for (int j = 0; j < m; j++)
      //{ //pr[h++] = *min_element(a[j], a[j] + ind[j]);
        //if (pr[h - 1] > max1)
        //{ max1 = pr[h - 1]; index = h - 1; }
       //}
       //cout << "max1 = " << max1 << endl;
       for (int j = 0; j <= m; j++)
       { if (a[j][0] > max1)
         { max1 = a[j][0]; indexes = j; }
        }
       
       //printf("%d\n", max1);
       answer[g++] = max1;
       max1 = 0;
       a[indexes][0] = 0;
       sort(a[indexes], a[indexes] + ind[indexes], greater<int>());
       ind[indexes]--;
     }
   }
  
  for (int i = 0; i < g; i++)
  cout << answer[i] << endl;
}

int main()
{ 
  in();
  
  //cin >> n;
  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
*/
