#include <stdio.h>
  
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <random>
#include <chrono>
#include <queue>
#include <functional>
#include <iostream>
#include <queue>
//#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ld long double
  
const ll maxn = 3e6 + 1, maxm = 1e7 + 1;
const ll mod = 1500000059, mod2 = 998244353, inf = 1e9, block = 550, hb = 1000012337, base = 1000050017;
const ld eps = 1e-3;
  
int n;
int x = 1;
int a[maxn], sz[maxn], h[maxn], ans[maxn];
vector<int> g[maxn], answ;
void build(int v = 1, int tl = 1, int tr = x){
    if (tl == tr){
        h[v] = 1;
        return;
    }
    int tm = (tl + tr) / 2;
    build(v + v, tl, tm);
    build(v + v + 1, tm + 1, tr);
    h[v] = h[v + v] + 1;
}
void check(int v = 1, int tl = 1, int tr = x){
   // cout << v << " " << ans[v] << '\n';
    if (tl == tr){
        answ.pb(ans[v]);
        return;
    }
    int tm = (tl + tr) / 2;
    check(v + v, tl, tm);
    check(v + v + 1, tm + 1, tr);
    if (!(ans[v] <= ans[v + v] && ans[v] <= ans[v + v + 1])){
        cout << -1;
        exit(0);
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n;
    map<int, int> was;
    set<int> setikk;
    for (int i = 1; i <= n; ++i){
        cin >> a[i];
        was[a[i]] += 1;
        setikk.insert(a[i]);
    }
    int sum = 1;
    int mx = 1;
    while (sum != n){
        x *= 2;
        sum += x;
        mx += 1;
    }
    if ((int)setikk.size() != x){
        cout << -1;
       // cout << (int)setikk.size() << " " << x << '\n';
        exit(0);
    }
    build();
    set<pair<int, int>> setik;
    set<pair<int, int>> seg;
    for (int i = 1; i <= n; ++i){
        if (was[a[i]] > 0){
            setik.insert(mp(was[a[i]], a[i]));
        }
        seg.insert(mp(h[i], i));
      //  cout << h[i] << " " << i << '\n';
    }
    //cout << "end\n";
    while (setik.size() > 0){
        pair<int, int> cur = *setik.rbegin();
        setik.erase(cur);
        int height = cur.f, z = cur.s;
        pair<int, int> cur2 = *seg.rbegin();;;
        if (cur2.f == height){
            int v = cur2.s;
            while (1){
                ans[v] = z;
                seg.erase(mp(h[v], v));
                if (v + v <= n && ans[v + v] == 0){
                    v = v + v;
                }
                else if (v + v + 1 <= n && ans[v + v + 1] == 0){
                    v = v + v + 1;
                }
                else{
                    if (v + v <= n || v + v + 1 <= n){
                        cout << -1;
                        exit(0);
                    }
                    break;
                }
            }
        }
        else{
           // cout << "lole\n";
            cout << -1;
            exit(0);
        }
     //   cout << "kek\n";
    }
   // cout << "lol\n";
   // cout << "fug\n";
    check();

    for (auto it : answ){
        cout << it << " ";
    }
}
