#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<tuple<long long,long long,long long>> a(n);
  for(int i=0;i<n;i++){
    cin>>get<0>(a[i])>>get<1>(a[i])>>get<2>(a[i]);
    get<2>(a[i])=max(0ll,get<2>(a[i])-get<0>(a[i]));
    if(get<2>(a[i])==0) get<0>(a[i])=10*10*10*10*10*10*10*10*10+1;
  }
  sort(a.begin(),a.end());
  if(get<0>(a[0])==10*10*10*10*10*10*10*10*10+1) cout<<-1<<endl;
  else{
  long long ans=10*10*10*10*10*10*10*10*10+1;
  int w=0;
  while(get<0>(a[w])<10*10*10*10*10*10*10*10*10+1){
    ans=min(ans,get<1>(a[w]));
    w++;
  }
    cout<<ans<<endl;
  }
}

#include<bits/stdc++.h>
using namespace std;
int main() {

	long long n, a, b, x, mn = 10000000000, pre = 0, d = 0;
	cin>>n;
	while(n--){
		cin>>a>>b>>x;
		d = d + a - pre;
		x = x - d;
		if(x > 0) mn = min(mn, b);
		pre = a;
	}
	if(mn == 10000000000) cout<<-1<<endl;
	else cout<<mn<<endl;
	return 0;
}
