#include <bits/stdc++.h>  // clang-format off
using namespace std;
using Int = long long;
#define REP2(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REP3(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define OVERLOAD2(_1, _2, _3, name, ...) name
#define REP(...) OVERLOAD2(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
struct in {
    int n; in() {} in(int n_) : n(n_){}
    template <class T> operator T() { T ret; cin >> ret; return ret; }
    template <class T> operator vector<T>() { vector<T> ret(n); for (int i = 0; i < n; i++) cin >> ret[i]; return ret; }
};
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat Jan 11 20:00:19 JST 2020
 **/

template <class T, class F> struct SegmentTree {
    const F op;
    const T e;
    SegmentTree(F op_, T e_) : op(op_), e(e_) {}
    int n;
    vector<T> t;
    void set_by_identity(int n_) {
        n = n_;
        t.clear(), t.resize(2 * n, e);
    }
    void set_by_vector(const vector<T>& a) {
        n = a.size();
        t.clear(), t.resize(2 * n, e);
        for (int i = 0; i < n; i++) t[i + n] = a[i];
        build();
    }
    void build() {
        for (int i = n - 1; i; --i) t[i] = op(t[2 * i], t[2 * i + 1]);
    }
    T& operator[](int i) { return t[i + n]; }
    // [l, r)
    T query(int l, int r) const {
        assert(0 <= l && l <= r && r <= n);
        T resl = e, resr = e;
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) resl = op(resl, t[l++]);
            if (r & 1) resr = op(t[--r], resr);
        }
        return op(resl, resr);
    }
    // iをaに変更
    void update(int i, const T& x) {
        assert(0 <= i && i < n);
        t[i += n] = x;
        while (i >>= 1) t[i] = op(t[2 * i], t[2 * i + 1]);
    }
    friend string to_string(const SegmentTree<T, F>& seg) {
        return to_string(vector<T>(seg.t.begin() + seg.n, seg.t.end()));
    }
};
template <class T, class F> auto make_segment_tree(F op, T e) { return SegmentTree<T, F>(op, e); }
// example
//     auto seg_ma = make_segment_tree<Int>([](Int a, Int b) { return max(a, b); }, -1e18);
//     auto seg_affine = make_segment_tree<pair<Int, Int>>(
//         [](pair<Int, Int> a, pair<Int, Int> b) -> pair<Int, Int> {
//             return {a.first * b.first, b.first * a.second + b.second};
//         },
//         {1, 0});

using pii = pair<Int, Int>;
signed main() {
    Int n = in();
    vector<Int> a(n + 1, -1);
    REP(i, n) cin >> a[i], a[i]--;
    if (n == 2) {
        cout << -1 << endl;
        return 0;
    }
    auto seg = make_segment_tree<pii>([](pii a, pii b) { return max(a, b); }, {-1, -1});
    vector<pii> in_dig(n);
    REP(i, n) {
        in_dig[i].second = i;
        in_dig[a[i]].first++;
    }
    seg.set_by_vector(in_dig);

    set<Int> s;
    REP(i, n) s.insert(i);
    vector<Int> ans;
    Int cur = n;
    REP(_, n) {
        if (cur != n) {
            auto p2 = seg.query(a[cur], a[cur] + 1);
            // assert(p2.second == a[cur]);
            seg.update(a[cur], {p2.first - 1, a[cur]});
            seg.update(cur, {-1, cur});
        }
        Int nxt = -1;
        auto p = seg.query(0, n);
        if (p.first == (Int)s.size()) {
            dump(cur, p);
            cout << -1 << endl;
            return 0;
        } else if (p.first == (Int)s.size() - 1 && s.count(p.second)) {
            dump(cur, p);
            nxt = p.second;
        } else if (s.size() == 3) {
            int x = *(next(s.begin(), 0));
            int y = *(next(s.begin(), 1));
            int z = *(next(s.begin(), 2));
            if (a[x] == y && a[y] == x) {
                nxt = a[cur] == x ? y : x;
            } else if (a[y] == z && a[z] == y) {
                nxt = a[cur] == y ? z : y;
            } else if (a[z] == x && a[x] == z) {
                nxt = a[cur] == x ? z : x;
            } else {
                nxt = a[cur] == *s.begin() ? *next(s.begin()) : *s.begin();
            }
        } else {
            nxt = a[cur] == *s.begin() ? *next(s.begin()) : *s.begin();
        }
        if (cur == nxt || !s.count(nxt)) {
            cout << -1 << endl;
            return 0;
        }
        cur = nxt;
        ans.push_back(cur);
        s.erase(cur);
    }
    dump(ans);
    assert(s.size() == 0 && ans.size() == n);
    for (Int x : ans) cout << x + 1 << " ";
    cout << endl;
}


Measured memory_bytes: 11008