#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define Pii pair<int,int>
#define Pll pair<long long,long long>
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));

using namespace std;

signed main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> p(n);
    vector<int> idx(n);
    vector<bool> use(n,false);
    rep(i,n){
        cin >> p[i];
        p[i]--;
        idx[p[i]]=i;
    }
    vector<int> ans;
    rep(i,n){
        int x = idx[i];
        //cout << x << endl;
        for(int j=x;j>i;j--){
            if(use[j]){
                cout << -1 << endl;
                return 0;
            }
            ans.pb(j);
            idx[p[j]]=j-1;
            idx[p[j-1]]=j;
            swap(p[j],p[j-1]);
            use[j] = true;
        }
    }
    if(ans.size()!=n-1) cout << -1 << endl;
    else{
        for(int u:ans) cout << u << endl;
    }
    return 0;
}
// g++ main.cpp -o a.out && ./a.out
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cctype>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <string>
#include <sstream>
#include <stack>
#include <set>
#include <vector>

#define rep(i,a,b) for((i)=a;i<(int)(b);i++)

const int AAA = 1000000007;


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;
typedef vector<int> vecI;

ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i = 0; i < b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}


int main(int argc, char* argv[]) {
	int i, j;
	string N;
	cin >> N;
	if (N.size() == 1) {
		cout << 0;
		return 0;
	}
	if (N.size() % 2 == 1) {
		string S;
		rep(i, 0, N.size() - 1) {
			S.push_back('9');
		}
		N = S;
	}
	ll shift_len = N.size() / 2;
	ll shift = pow(10, shift_len);

	ll X = stoll(N);
	ll n1 = stoll(N) / shift;
	ll n2 = stoll(N) % shift;

	ll n = pow(10, shift_len-1);
	ll ans = pow(10, shift_len - 1) - 1;
	while (n * shift + n <= X) {
		ans++;
		n++;
	}
	cout << ans;
	return 0;
}

