#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<string.h>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cmath>
typedef long long ll; 
using namespace std;
int main()
{
	int n;
	cin >> n;
	int ans=0x3f3f3f3f;
	for(int i=1;i<=n;i++){
		int a,b,c;
		cin >> a >> b >> c;
		if(c-a>0){
			ans=min(ans,b);
		}
	}
	if(ans==0x3f3f3f3f){
		ans=-1;
	}
	cout << ans << endl;
	return 0;
 } 
#pragma GCC optimize("Ofast")
//#ifndef ONLINE_JUDGE 
//#define _GLIBCXX_DEBUG
//#endif
#ifdef ONLINE_JUDGE 
#include <atcoder/all>
#endif
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <math.h>
#include <complex>
 
 
using namespace std;
#ifdef ONLINE_JUDGE 
using namespace atcoder;
#endif
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
#ifdef ONLINE_JUDGE 
//using mint = modint998244353;
//using mint = modint;
using mint = modint1000000007;
#endif
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int dy[9] = {0, 1, 0, -1, 1, -1, -1, 1, 0};
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
 
 
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);
 
  ll N; cin>>N;
  vector<tuple<ll,ll,ll>> v(N); 
  rep(i,N) {
    ll a,p,x; cin>>a>>p>>x;
    v[i]={a,p,x};
  }
  sort(v.begin(),v.end());
  
  ll ans=INF;
  for(auto &[a,p,x]:v) {
    if(x-a>0) chmin(ans,p);
  }
  
  cout<<(ans<INF?ans:-1)<<'\n';
  
  return 0;
}