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

int main() {

  int n;
  cin >> n;
  
  vector<vector<int>> data(n, vector<int>(3));
 
 for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> data.at(i).at(j);
    }
  }
  
  int res = -1;
  int price = data.at(0).at(1);
  for (int i =0; i < n; i++){
   if(data.at(i).at(2) - data.at(i).at(0) > 0){
     if(price > data.at(i).at(1)){
       price = data.at(i).at(1);
       res = data.at(i).at(1);
     }
   }
  }
  
  cout << res << endl;
  
}

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


int main(){
int N;
cin >>N;
vector<long long>A(N);
vector<long long>P(N);
vector<long long>X(N);
vector<long long>l(N);
for(int i = 0;i<N;i++){
  cin>>A[i]>>P[i]>>X[i];
}

for(int i = 0;i<N;i++){
  if(A[i] < X[i]){
    l[i] = P[i];
  }
  else{
    l[i] = 1000000001;
  }
}
long long m = 1000000001;

for(int i = 0;i<N;i++){
    m = min(l[i],m);
}

if(m == 1000000001){
  m = -1;
}

cout<<m<<endl;
}

