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

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << ", " << a.second << ")";
  return out;
}

template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "[";
  bool first = true;
  for (auto& v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "]";
  return out;
}

template<typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "[";
  bool first = true;
  for (auto& v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "]";
  return out;
}

template<typename T>
ostream& operator <<(ostream& out, const vector<vector<T>>& a) {
  bool first = true;
  for (auto& v : a) {
    if (!first)
      out << "   ";
    for (auto& p : v)
      out << p << "  ";
    out << "\n";
    first = 0;
  }
  return out;
}

template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{";
  bool first = true;
  for (auto& v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "}";
  return out;
}

template <typename T, class Cmp>
ostream& operator <<(ostream& out, const multiset<T, Cmp>& a) {
  out << "{";
  bool first = true;
  for (auto& v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{";
  bool first = true;
  for (auto& p : a) {
    out << (first ? "" : ", ");
    out << p.first << ":" << p.second;
    first = 0;
  }
  out << "}";
  return out;
}

#ifdef LOCAL
#define debug(...) dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) 0
#endif

template <typename Arg1>
void dbg(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void dbg(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  dbg(comma + 1, args...);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> p(n), pos(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    pos[p[i]] = i;
  }
  vector<int> b(n);
  iota(b.begin(), b.end(), 1);
  vector<bool> swapped(n);
  vector<int> res;
  for (int i = 0; i < n; i++) {
    if (p[i] != b[i]) {
      int idx = pos[b[i]];
      while (idx > i) {
        if (swapped[idx - 1]) {
          cout << "-1\n";
          return 0;
        } 
        swap(p[idx - 1], p[idx]);
        swap(pos[idx - 1], pos[idx]);
        swapped[idx - 1] = true;
        res.emplace_back(idx);
        --idx;
      }
    }
  }
  if (res.size() != (n - 1))
    cout << "-1\n";
  else {
    for (int& p : res)
      cout << p << '\n';
  }
  return 0;
}
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}
#ifdef _GLIBCXX_DEBUG
void _debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void _debug_out(Head H, Tail... T) { cerr << " " << H; _debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", _debug_out(__VA_ARGS__)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#define eprintf(...)
#endif

int main() {
  int n; cin >> n;
  int INF=int(1e9)+1;
  int ans = INF;

  rep(i,n) {
    int a,p,x;
    cin >> a >> p >> x;
    if(x <= a) continue;
    umin(ans,p);
  }
  if(ans==INF) ans = -1;
  cout << ans << endl;
}
