#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

template<typename Monoid> struct Segment_Tree{
    //二項演算
    Monoid ope(Monoid a, Monoid b){
        return min(a, b);
    }
    //単位元
    Monoid unit;
    int n;
    vector<Monoid> seg;
    //要素数N(0-indexed)のxを単位元とするセグメント木を構築
    Segment_Tree(int N, Monoid x){
        unit = x;
        n = 1;
        while(n < N) n <<= 1;
        seg.assign(2*n, unit);
    }
    //i番目の要素をxに変更
    void change(int i, Monoid x){
        i += n;
        seg[i] = x;
        while(i > 0){
            i /= 2;
            seg[i] = ope(seg[2*i], seg[2*i+1]);
        }
    }
    //query(a, b)で[a, b)における演算の結果を取得
    Monoid query(int a, int b, int i = 1, int l = 0, int r = -1){
        if(r < 0) r = n;
        if(a >= r || b <= l) return unit;
        if(a <= l && r <= b) return seg[i];
        Monoid vl = query(a, b, 2*i, l, (l+r)/2);
        Monoid vr = query(a, b, 2*i+1, (l+r)/2, r);
        return ope(vl, vr);
    }
    //i番目の要素を取得
    Monoid at(int i){
        return seg[n+i]; 
    }
    //初期化する
    void clear(){
        fill(seg.begin(), seg.end(), unit);
    }
};

int main(){
    int N;
    cin >> N;
    int a[N];
    Segment_Tree<int> seg1(N, inf), seg2(N, inf);
    priority_queue<int, vector<int>, greater<int> > que;
    rep(i, N){
        cin >> a[i]; a[i]--;
        seg1.change(i, a[i]), seg2.change(i, -a[i]);
        que.push(i);
    }
    if(N == 2) {cout << -1 << endl; return 0;}
    int pre = -1;
    bool used[N];
    fill(used, used+N, false);
    vector<int> ans;
    rep(n, N-3){
        vector<int> memo;
        while(true){
            int i = que.top();
            que.pop();
            if(used[i]) continue;
            if(pre != -1 && a[pre] == i){
                memo.pb(i);
                continue;
            }
            int j = a[i];
            seg1.change(i, inf), seg2.change(i, inf);
            seg1.change(j, inf), seg2.change(j, inf);
            if(!used[j] && seg1.query(0, N) == j && seg2.query(0, N) == -j){
                memo.pb(i);
                ans.pb(j);
                pre = j, used[j] = true;
                seg1.change(i, a[i]), seg2.change(i, -a[i]);
            }
            else{
                ans.pb(i);
                pre = i, used[i] = true;
                if(!used[j]) seg1.change(j, a[j]), seg2.change(j, -a[j]);
            }
            break;
        }
        for(auto &e: memo) que.push(e);
    }
    vector<int> rem;
    while(!que.empty()){
        int i = que.top(); que.pop();
        if(!used[i]) rem.pb(i);
    }
    do{
        if(pre != -1 && a[pre] == rem[0]) continue;
        if(a[rem[0]] == rem[1] || a[rem[1]] == rem[2]) continue;
        rep(i, 3) ans.pb(rem[i]);
        break;
    } while(next_permutation(all(rem)));
    if(sz(ans) != N) cout << -1 << endl;
    else{
        for(auto &e: ans) cout << e+1 << ' '; cout << endl;
    }
}

Measured memory_bytes: 4344