#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    int n, q, a, t, x;
    cin >> n >> q;
    vector< priority_queue<ll> > que(n);
    while (q--) {
        cin >> a;
        switch (a) {
            case 0:
                cin >> t >> x;
                que[t].push(x);
                break;
            case 1:
                cin >> t;
                if (!que[t].empty())
                    cout << que[t].top() << endl;
                break;
            case 2:
                cin >> t;
                if (!que[t].empty())
                    que[t].pop();
                break;
        }
    }
    return 0;
}
