#include <bits/stdc++.h>
using namespace std;
struct BIT{
    vector<long long> num;
    int N;
    BIT(int n){
        N = n;
        num.resize(N + 1, 0);
    }
    long long sum(long long t){
        long long res = 0;
        while(t > 0){
            res += num[t];
            t -= t & -t;
        }
        return res;
    }
    void add(int ind, long long t){
        ind++;
        while(ind <= N){
            num[ind] += t;
            ind += ind & -ind;
        }
    }
};
int main(){
    int N;
    cin >> N;
    vector<int> P(N);
    for(int i = 0; i < N; i++) {
        cin >> P[i];
        P[i]--;
    }
    BIT bit(N);
    vector<int> ind(N);
    for(int i = 0; i < N; i++) ind[i] = i;
    sort(ind.begin(), ind.end(), [&](int x, int y){
        return P[x] < P[y];
    });
    long long sum1 = 0;
    for(int i = 0; i < N; i++){
        bit.add(ind[i], 1);
        sum1 += bit.sum(N) - bit.sum(ind[i] + 1);
    }
    if(sum1 != N - 1){
        cout << -1 << endl;
        return 0;
    }
    vector<int> ans;
    set<int> s;
    int ind2 = N - 1;
    while(1){
        if(ind2 < 0) break;
        int tem = ind[ind2];
        for(int i = 0; i < ind2 - tem; i++){
            ans.push_back(ind[ind2]);
            if(s.count(ind[ind2])){
                cout << -1 << endl;
                return 0;
            }
            s.insert(ind[ind2]);
            swap(ind[ind2], ind[P[ind[ind2] + 1]]);
        }
        ind2--;
    }
    for(int i = 0; i < (int)ans.size(); i++){
        cout << ans[i] + 1 << endl;
    }
}
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) cout<<i<<" ";puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
	ll x=0,f=1;char c=getchar();
	while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
	if (c=='-') f=-1,c=getchar();
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}

const int N = 2e5+10;
int n,a[N],pos[N];

bool vis[N];
poly ans;
inline void Swap(int x,int y){
	if (vis[x]){
		puts("-1");
		exit(0);
	}
	vis[x]=1,swap(pos[a[x]],pos[a[y]]),swap(a[x],a[y]);
	ans.pb(x);
}

int main(){
	n=read();
	For(i,1,n) a[i]=read(),pos[a[i]]=i;
	FOR(i,1,n){
		while (a[i]!=i) Swap(pos[i]-1,pos[i]);
	}
	if (siz(ans)!=n-1) return puts("-1"),0;
	For(i,1,n-1) printf("%d\n",ans[i-1]);
}