#include <cstdio>
#include <queue>
using namespace std;
 
int main() {
  int n, q; scanf("%d %d", &n, &q);
  vector< priority_queue<int> > nums(n);
   
  while (q--) {
    int command, t; scanf("%d %d", &command, &t);
     
    switch (command) {
      case 0:
        int x; scanf("%d", &x);
        nums[t].push(x);
        break;
         
      case 1:
        if (!nums[t].empty()) printf("%d\n", nums[t].top());
        break;
         
      case 2:
        if (!nums[t].empty()) nums[t].pop();
        break;
    }
  }
}
