#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
typedef pair<pi, ll> pii;
typedef pair<ll, pi> ipi;
typedef pair<pi, pi> pipi;
#define mp make_pair
#define f first
#define s second
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define size(v) (ll) v.size()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define memset(x, v) memset(x, v, sizeof x)
#define INF (ll) (1e9 + 100)
#define LLINF (ll) 1e18
#define mod (const ll) (1e9 + 7)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge")))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusive

ll n, a, b, c, ans = LLINF;

int main() {
	fastio; cin >> n;
	FOR(i, 1, n) {
		cin >> a >> b >> c;
		if (c > a) ans = min(ans, b);
	}
	cout << (ans == LLINF ? -1 : ans);
}

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <cstdio>
#include <stack>
#include <cstring>


//#define FILE_INPUT


using namespace std;


#define inc(i, n) for (int i = 0; i < (n); i++)
#define incs(i, st, n) for (int i = (st); i < (n); i++)
using ll = long long;


constexpr int LIMIT = 0x3f3f3f3f;

template <typename T>
ll inv(T bg, T nd) {
    if (nd - bg <= 1) return 0;

    T md = bg + (nd - bg) / 2;
    ll ret = inv(bg, md) + inv(md, nd);

    auto i = bg, j = md;
    while (i != md) {
        while (j != nd && *i > *j) {
            j++;
        }
        ret += j - md;
        i++;
    }

    inplace_merge(bg, md, nd);
    return ret;
}

int main(int argc, char** argv){
#ifdef FILE_INPUT
    freopen("input", "r", stdin);
#endif

    int N;
    scanf("%d", &N);

    vector<int> a(N, 0);
    inc(i, N) {
        scanf("%d", &a[i]);
    }

    // calc inv number
    vector<int> b(a.begin(), a.end());
    ll inv_num = inv(b.begin(), b.end());
    printf("%lld\n", inv_num);

    inc(i, N-1) {
        inv_num = inv_num + N - a[i]*2 -1LL;
        printf("%lld\n", inv_num);
    }




#ifdef FILE_INPUT
    fclose(stdin);
#endif
  	return 0;
}