#include <iostream>
#include <string>
#include <bits/stdc++.h>

using namespace std;

int main(){
  int n;
  cin >> n;
  
  vector<vector<int>> v (n, vector<int>(3));
  for (int i = 0; i < n; i++) {
      cin >> v[i][0] >> v[i][1] >> v[i][2];
      }
  vector<int> a(n), p(n), x(n);
  int counter = 0, min_price = 1000000000;
  for (int i = 0; i < n; i++){
    a[i] = v[i][0], p[i] = v[i][1], x[i] = v[i][2];  
    if (x[i] - a[i] <= 0){
      counter++;
    }
    else{
      min_price = min (p[i], min_price);
    }
  }  
  
  if (counter == n) cout << -1 << endl;  
  else cout << min_price << endl;
  return 0;
}
  
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    auto nc2 = [](ll n){return n * (n-1) / 2;};
    int n; cin >> n;
    ll ans = 0;
    REP(i,n) {
        int a, b;
        cin >> a >> b;
        ans += nc2(b+1) - nc2(a);
    }

    cout << ans << '\n';

    return 0;
}