#include <iostream>
#include <vector>
#include <set>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> p(n + 1), pos(n + 1), ans;
    set<int> s;
    for (int i = 1; i <= n; ++i) {
        cin >> p.at(i), pos.at(p.at(i)) = i;
        if (i != n) s.insert(i);
    }
    for (int i = 1; i <= n; ++i) {
        while (pos.at(i) > i) {
            if (s.count(pos.at(i) - 1)) ans.push_back(pos.at(i) - 1), s.erase(pos.at(i) - 1), --pos.at(i), ++pos.at(p.at(pos.at(i))), swap(p.at(pos.at(i)), p.at(pos.at(i) + 1));
            else {
                cout << "-1\n";
                return 0;
            }
        }
        while (pos.at(i) < i) {
            if (s.count(pos.at(i) + 1)) ans.push_back(pos.at(i) + 1), s.erase(pos.at(i) + 1), ++pos.at(i), --pos.at(p.at(pos.at(i))), swap(p.at(pos.at(i)), p.at(pos.at(i) - 1));
            else {
                cout << "-1\n";
                return 0;
            }
        }
    }
    if (s.size()) cout << "-1\n";
    else for (const auto& i : ans) cout << i << '\n';
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 2e5+5;

int n, a[sz], w[sz], bit[sz];

void add(int x) {
   while(x <= n) {
      bit[x]++;
      x += x & (-x);
   }
}

int quer(int x) {
   int ans = 0;
   while(x) {
      ans += bit[x];
      x -= x & (-x);
   }
   return ans;
}

int main() {
   cin >> n;
   for(int i=1; i<=n; i++) scanf("%d", &a[i]), w[a[i]] = i;

   int tot = 0;
   vector <int> res;
   for(int i=n; i; i--) {
      int x = quer(w[i]);
      if(x) tot += x, res.push_back(x);
      add(w[i]);
   }
   if(tot == n-1) {
      reverse(res.begin(), res.end());
      int s = 0;
      for(int x : res) {
         for(int i=s+x; i>s; i--) printf("%d\n", i);
         s += x;
      }
   }
   else puts("-1");
}
