//#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;
}
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
#include<set>
#include <array>
using namespace std;
#define ll long long
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define con continue
#define ub upper_bound
#define lb lower_bound

#define si(x) int(x.size())
#define sum_all(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
const double pi = 2 * acos(0.0);
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, -1, 0, 1 };

const int dx8[] = { -1, 0, 1, 0,1,1,-1,-1 };
const int dy8[] = { 0, -1, 0, 1,1,-1,1,-1 };

ll min(ll a,ll b)
{
    if(a<b)return a;
    return b; 
}
ll max(ll a,ll b)
{
    if(a>b)return a;
    return b; 
}
ll ceil1(ll a,ll b)
{
    return(a+b-1)/b;
}
void read(vector<ll> & arr)
{
  for(ll i=0;i<si(arr);i++)
    cin >> arr[i];

}

void read_graph(vector<vector<ll>>& g, ll m)
{
  while(m--)
  {
    ll x,y; cin >> x>> y ;
    x--,y--; 
    g[x].pb(y);
    g[y].pb(x);
  }
}
void solve()
{
 
  int n;
  cin >>n ;
  vector<int> arr(n+1);
  vector<int> ind(n+1);

  for(int i=1;i<=n;i++)
   {
     cin >> arr[i];
     ind[arr[i]]=i;
   }


   vector<bool> vis(n);
   vector<int> ans ; 
   bool yes=true; 
   for(int i=1;i<=n;i++)
   {
     int u=ind[i];
     if(ind[i]==i) continue;
     while(u>i)
     {
       
       if(vis[u-1]) 
       {
         yes=false;
         break; 
       }
       // cout << u << endl;
       vis[u-1]=true;
       ans.pb(u-1);
       swap(arr[u],arr[u-1]);
       ind[arr[u]]=u;
       ind[arr[u-1]]=u-1;
       u--;
     }

    
     if(!yes) break; 
     // cout << i << endl;
   }
    // cout << yes << endl;
   for(int i=1;i<n;i++)
    {
      if(!vis[i]) yes=false;
    }
    // cout << endl;
    
    for(int i=1;i<=n;i++)
      if(arr[i]!=i) yes=false;
    if(!yes) cout << -1 ;
    else 
    {
       for(int i=0;i<n-1;i++) cout << ans[i] << " ";
    }
  cout << endl; 


}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    //int t; cin >> t; while (t--)
    solve();

}
