#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> time(N);
  vector<int> price(N);
  vector<int> zaiko(N);
  for(int i=0;i<N;i++){
    cin >> time.at(i);
    cin >> price.at(i);
    cin >> zaiko.at(i);
  }
  bool b = false;
  int min=1000000001;
  for(int i=0;i<N;i++){
    if(time.at(i)<zaiko.at(i)&&price.at(i)<min){
      min=price.at(i);
      b=true;
    }
  }
  if(b==true){
    cout << min << endl;
  }
  else{
    cout << -1 << endl;
  }
}
#include <bits/stdc++.h>
using namespace std;

template<typename T, typename Y> inline void mint(T & x,Y y) {if(y < x) x = y;} 
template<typename T, typename Y> inline void maxt(T & x,Y y) {if(y > x) x = y;}
#define si(x) static_cast<int>(x.size())
typedef int64_t ll;
constexpr int mod = (int) 1'000'000'007;
constexpr int maxn = (int) 2e5+5;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

auto solve() -> decltype(auto){
	int n;
	cin >> n;
	using triplet = tuple<int,int,int>;

	vector<triplet> A(n);

	for(int i = 0;i < n;i++){
		auto & [l,r,idx] = A[i];
		idx = i;
		cin >> l >> r;
	}


	auto x_compare = [](const triplet & _a,const triplet & _b){
		return get<0>(_a) < get<0>(_b);
	};

	auto y_compare = [](const triplet & _a,const triplet & _b){
		return get<1>(_a) < get<1>(_b);
	};

	vector<pair<int,int>> cands;

	set<int> taken;

	sort(A.begin(),A.end(),x_compare);

	for(int i = 0;i < min(si(A),5);i++){
		auto & [l,r,idx] = A[i];
		cands.push_back({l,r});
		taken.insert(idx);
	}
	for(int i = n-1;i >= max(0,si(A)-5);i--){
		auto & [l,r,idx] = A[i];

		if(taken.count(idx)) continue;

		cands.push_back({l,r});
		taken.insert(idx);
	}
	sort(A.begin(),A.end(),y_compare);

	for(int i = 0;i < min(si(A),5);i++){
		auto & [l,r,idx] = A[i];
		if(taken.count(idx)) continue;
		cands.push_back({l,r});
		taken.insert(idx);
	}

	for(int i = n-1;i >= max(0,si(A)-5);i--){
		auto & [l,r,idx] = A[i];
		if(taken.count(idx)) continue;
		cands.push_back({l,r});
		taken.insert(idx);
	}
	vector<int> posib;

	for(int i = 0;i < si(cands);i++){
		for(int j = i+1;j < si(cands);j++){
			posib.push_back(max(abs(cands[i].first-cands[j].first),abs(cands[i].second-cands[j].second)));
		}
	}

	sort(posib.rbegin(),posib.rend());

	cout << posib[1] << '\n';
}

int32_t main(void){
	ios::sync_with_stdio(false);cin.tie(0);
	uint32_t tcs = 1;
	// cin >> tcs;
	for(uint32_t i = 1;i <= tcs;i++) solve();
}
