#include <iostream>
#include <vector>

using namespace std;

template<typename T>
class SegTree {
public:
    explicit SegTree(int n, T def) : N(calcN_(n)), def(def), mVal(2*calcN_(n)-1, def) {}
    void update(int idx, T value){
        int i = N + idx - 1;
        update_(mVal[i], value);
        while(i > 0){
            i = (i-1)/2;
            mVal[i] = operate(mVal[2*i+1], mVal[2*i+2]);
        }
    }
    T get(int l, int r){
        return getImpl_(l, r, 0, 0, N);
    }
private:
    int calcN_(int n){
        int res = 1;
        while(res < n) res *= 2;
        return res;
    }
    T getImpl_(int l, int r, int idx, int rangeL, int rangeR){
        if(r <= rangeL || rangeR <= l) return def;
        if(l <= rangeL && rangeR <= r) return mVal[idx];
        int rangeM = (rangeL+rangeR)/2;
        T a = getImpl_(l, r, 2*idx+1, rangeL, rangeM);
        T b = getImpl_(l, r, 2*idx+2, rangeM, rangeR);
        return operate(a, b);
    }
    T update_(T& data, T val) { data = val; }
    T operate(T a, T b) { return max(a, b); }
    const int N;
    const T def;
    vector<T> mVal; 
};

int main(){
    int N;
    while(cin >> N){
        vector<int> b(N);
        vector<int> ng(N, 0);
        for(auto& t : b){
            cin >> t; --t;
            ng[t]++;
        }
        SegTree<int> ngt(N, 0);
        SegTree<int> exist(N, 0);
        for(int i=0;i<N;i++){
            ngt.update(i, ng[i]);
            exist.update(i, 1);
        }
        if(N == 2){
            cout << -1 << endl;
            continue;
        }
        int prev = -1;
        vector<int> res;
        for(int i=0;i<N;i++){
            int sel = -1;
            if(i != N-1 && ngt.get(0, N) == N-1-i){
                int L = 0, R = N;
                while(R-L > 1){
                    int mid = (L+R)/2;
                    if(ngt.get(0, mid) == N-1-i) R = mid;
                    else L = mid;
                }
                sel = R-1;
            } else if(i == N-3){
                vector<int> rest;
                for(int j=0;j<N;j++) if(exist.get(j, j+1) == 1) rest.push_back(j);
                for(int j=0;j<3;j++){
                    for(int k=j+1;k<3;k++){
                        if(b[rest[j]] == rest[k] && b[rest[k]] == rest[j] && ng[rest[j]] == ng[rest[k]]){
                            sel = (prev != rest[j] ? rest[j] : rest[k]);
                        }
                    }
                }
            }
            if(sel == -1){
                bool del = (prev != -1 && exist.get(prev, prev+1) == 1);
                if(del) exist.update(prev, 0);
                int L = 0, R = N;
                while(R-L > 1){
                    int mid = (L+R)/2;
                    if(exist.get(0, mid) == 1) R = mid;
                    else L = mid;
                }
                sel = R-1;
                if(del) exist.update(prev, 1);
            }
            ngt.update(sel, 0);
            if(exist.get(b[sel], b[sel]+1)){
                ng[b[sel]]--;
                ngt.update(b[sel], ng[b[sel]]);
            }
            exist.update(sel, 0);
            prev = b[sel];
            res.push_back(sel+1);
        }
        cout << res[0];
        for(int i=1;i<N;i++) cout << " " << res[i];
        cout << endl;
    }
}

Measured memory_bytes: 4216