#include <bits/stdc++.h>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> a(N);
    for (int i=0;i<N;++i) cin >> a[i];
    if (N==2){cout << -1 << '\n'; return 0;}
    vector<int> deg(N,0),used(N,0),ans(N,-1);
    for (int i=0;i<N;++i) ++deg[--a[i]];
    set<pair<int,int>> s;
    priority_queue<int,vector<int>,greater<int>> skipped;
    for (int i=0;i<N;++i) s.emplace(-deg[i],i);
    for (int i=0,now=0;i<N-3;++i){
        auto p=*s.begin();
        if (-p.first==N-1-i){
            ans[i]=p.second;
        } else if (!i){
            ans[i]=0;
        } else {
            if (!skipped.empty()){
                int x=skipped.top(); skipped.pop();
                if (a[ans[i-1]]!=x) ans[i]=x;
                else if (!skipped.empty()){
                    ans[i]=skipped.top();
                    skipped.pop(); skipped.emplace(x);
                } else skipped.emplace(x);
            }
            if (ans[i]<0){
                while(used[now]) ++now;
                if (a[ans[i-1]]==now) skipped.emplace(now++);
                while(used[now]) ++now;
                ans[i]=now;
            }
        }
        used[ans[i]]=1;
        s.erase({-deg[ans[i]],ans[i]});
        int nxt=a[ans[i]];
        if (used[nxt]) continue;
        s.erase({-deg[nxt],nxt});
        --deg[nxt];
        s.emplace(-deg[nxt],nxt);
    }
    vector<int> unused,res(3,N);
    for (int i=0;i<N;++i) if (!used[i]) unused.emplace_back(i);
    vector<int> perm(3);
    iota(perm.begin(),perm.end(),0);
    do {
        vector<int> cnt(3);
        for (int i=0;i<3;++i) cnt[i]=unused[perm[i]];
        if (N>3&&a[ans[N-4]]==cnt[0]) continue;
        if (a[cnt[0]]==cnt[1]) continue;
        if (a[cnt[1]]==cnt[2]) continue;
        res=min(res,cnt);
    } while(next_permutation(perm.begin(),perm.end()));
    for (int i=0;i<3;++i) ans[N-3+i]=res[i];
    for (int i=0;i<N;++i) cout << ans[i]+1 << (i+1==N?'\n':' ');
}