#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); }
template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n);  for(auto& a : v) init(a, x, m...); }
int n, q;
vector<map<int, int>> H;
vector<int> p;

int par(int x){
    if (p[x] == x)
        return x;
    return p[x] = par(p[x]);
}
void merge(int x, int y){
    int px = par(x);
    int py = par(y);
    if (px == py) return;
    if (H[px].size() < H[py].size())
        swap(px, py);
    p[py] = px;
    for(auto it : H[py])
        H[px][it.first] += it.second;
}
int get(int x, int ci){
    int px = par(x);
    return H[px][ci];
}

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    cin >> n >> q;
    p.resize(n+1);
    H.resize(n+1);
    FOR(i, n){
        int ci;
        cin >> ci;
        H[i+1][ci]++;
        p[i+1] = i+1;
    }

    FOR(i, q){
        int t, x, y;
        cin >> t >> x >> y;
        if (t == 1)
            merge(x, y);
        else
            cout << get(x, y) << '\n';
    }

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a) for(int i = 0; i < (int) a; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main(){
	ios::sync_with_stdio(false); cin.tie(0);

	int n; cin >> n;
	int ans = 1e9+7;

	FOR(i, n){
		int a, b, c; cin >> a >> b >> c;

		if(c > a) ans = min(ans, b);
	}

	if(ans == 1e9+7) cout << "-1\n";
	else cout << ans << '\n';

	return 0;
}