//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")

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

#define ll long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define inf 1000000000000000000
#define ff first
#define ss second
#define deb(x) cout<<#x<<" "<<x<<"\n"
#define Clear(x) memset(x,0,sizeof(x))
#define all(x) (x).begin(),(x).end()

void checkpoint1()
{
	/******think more code less******/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("Error.txt", "w", stderr);
	#endif
}

bool comp(pair< ll,ll > &a,pair< ll,ll > &b)
{
	if(a.ff!=b.ff)
		return a.ff<b.ff;
	else
	{
		if(a.ss>b.ss)
			return b.ss<a.ss;
		else if(a.ss<b.ss)
			return a.ss<b.ss;
	}
	return a.ff>b.ff;
}

ll powe(ll a,ll b)
{
	ll res=1;
	while(b>0)
	{
		if(b&1)
		{
			res*=a;
			res%=mod;
		}
		a*=a;
		a%=mod;
		b>>=1;
	}
	return res;
}
void upd(ll st[],ll v,ll stl,ll str,ll pos,ll val)
{
	if(stl==str)
		st[v]=1;
	else
	{
		ll stm=(stl+str)/2;
		if(pos<=stm)
			upd(st,2*v,stl,stm,pos,val);
		else
			upd(st,2*v+1,stm+1,str,pos,val);
		st[v]=st[2*v]+st[2*v+1];
	}
}
ll ans(ll st[],ll v,ll stl,ll str,ll l,ll r)
{
	if(l>r)
		return 0LL;
	if(stl==l && r==str)
		return st[v];
	else
	{
		ll stm=(stl+str)/2;
		return ans(st,2*v,stl,stm,l,min(r,stm))+ans(st,2*v+1,stm+1,str,max(stm+1,l),r);
	}
}
void terminAtor()
{
	ll n;
	cin>>n;
	ll a[n+1];
	for(ll i=1;i<=n;i++)
		cin>>a[i];
	ll st[4*(n+1)];
	for(ll i=0;i<4*n+1;i++)
		st[i]=0;
	ll tot=0,temp=0;
	vector< ll > pos;
	for(ll i=1;i<=n;i++)
	{
		tot+=(ans(st,1,1,n,a[i]+1,n));
		if(temp!=tot)
		{
			temp=tot;
			pos.pb(i);
		}
		upd(st,1,1,n,a[i],1);
	}
	if(tot!=n-1){
		cout<<-1;
		return;
	}
	ll k=0;
	for(ll i=0;i<pos.size();i++)
	{
		ll tt=pos[i]-1;
		pos[i]--;
		while(pos[i]>k)
		{
			cout<<pos[i]<<"\n";
			pos[i]--;
		}
		k=tt;
	}

}

int main()
{	
	checkpoint1();
/********************************************************/	
	auto startrrr = high_resolution_clock::now();
	cout << setprecision(20);
/*******************************************************/	
	
	terminAtor();


/*******************************************************/	
	auto stoprrr = high_resolution_clock::now();
	auto duration = duration_cast<microseconds>(stoprrr - startrrr);
	#ifndef ONLINE_JUDGE
		cerr << "Time: " << duration.count()/1000.0<<"\n";
	#endif
/*******************************************************/		
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int a[2000005], b[2000005],c[2000005];
int main()
{
    int n;
    cin >> n;
    for(int i=1;i<=n;i++) {
        cin >> a[i];
        b[a[i]]=i;
        c[i] = a[i];
    }

    unordered_map<int,int> mp;
    vector<int>v;
    for(int i=1;i<=n;i++)
    {
        for(int j = b[i]-1;j>=i;j--)
        {
            if(mp[j]==0){
            b[a[j]]++;
            a[j+1]= a[j];
            v.push_back(j);
            mp[j]=1;
            }

            else
            {
                cout << -1 << endl;
                return 0;
            }
        }
        b[i]=i;
        a[i]=i;


    }

    if(mp.size()==n-1)
    {
        for(auto it: v) cout << it << " ";
        cout << endl;
    }
    else cout << -1 << endl;
}
