#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int a[200001], A[200001];
map<int, int> mp, mp2;
vector<int> v[200001];
int n, k, m;
bool ok = 1;

void rec(int k, int l, int r, int val) {
    if (l == r) {
        if (val) {
            A[l] = val;
            return;
        } else {
            if (v[1].size() > 0) {
                A[l] = v[1].back();
                v[1].pop_back();
            } else {
                ok = 0;
            }
        }
        return;
    }
    if (val) {
        int md = (l + r) / 2;
        rec(k - 1, md + 1, r, 0);
        rec(k - 1, l, md, val);
    } else {
        int md = (l + r) / 2;
        if (v[k].size() > 0) {
            val = v[k].back();
            v[k].pop_back();
        } else {
            ok = 0;
        }
        rec(k - 1, md + 1, r, 0);
        rec(k - 1, l, md, val);
    }
}

int rec2(int k, int l, int r) {
    if (l == r) {
        mp2[A[l]]++;
        return A[l];
    }
    int md = (l + r) / 2;
    int x = rec2(k - 1, l, md);
    int y = rec2(k - 1, md + 1, r);
    mp2[min(x, y)]++;
    return min(x, y);
}

int main() {
    cin >> n;
    k = 1;
    int two = 2;
    while (two - 1 < n) {
        two *= 2;
        k++;
    }
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        mp[a[i]]++;
    }
    for (pair<int, int> i : mp) {
        int x = i.first, y = i.second;
        v[y].push_back(x);
    }
    two /= 2;
    rec(k, 1, two, 0);
    if (ok) {
        rec2(k, 1, two);
        for (pair<int, int> i : mp) {
            int x = i.first;
            if (i.second != mp2[x]) {
                cout << -1;
                return 0;
            }
        }
        for (int i = 1; i <= two; i++)
            cout << A[i] << " ";
    } else {
        cout << -1;
    }
    return 0;
}

