#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i], a[i]--;

    auto solve = [&] {
        if(n == 2) {
            // cout << -1 << endl;
            return vector<ll>(0);
        }

        map<ll, ll> mp;
        REP(i, n) mp[a[i]]++;
        set<ll> st;
        REP(i, n) st.insert(i);
        vector<ll> ans;
        REP(i, n) {
            ll mi = st.size() ? *st.begin() : INF;
            ll mi2 = st.size()>=2 ? *(next(st.begin())) : INF;
            dump(ans, st, mp);
            if(mp.size() == 2) {
                auto p1 = *mp.begin();
                auto p2 = *(next(mp.begin()));
                if(st.find(p1.first) != st.end() && p2.second == 1) {
                    ans.push_back(p1.first);
                    st.erase(p1.first);
                    mp[a[p1.first]]--;
                    if(mp[a[p1.first]] == 0) mp.erase(a[p1.first]);
                    continue;
                }
                if(st.find(p2.first) != st.end() && p1.second == 1) {
                    ans.push_back(p2.first);
                    st.erase(p2.first);
                    mp[a[p2.first]]--;
                    if(mp[a[p2.first]] == 0) mp.erase(a[p2.first]);
                    continue;
                }
            }
            if(st.size() == 3) {
                vector<ll> v;
                for(auto j: st) v.push_back(j);
                bool f0 = true, f1 = true, f2 = true;
                if(a[v[1]] == v[2] && a[v[2]] == v[1]) f0 = false;
                if(i && a[ans.back()] == v[0]) f0 = false;
                if(a[v[0]] == v[2] && a[v[2]] == v[0]) f1 = false;                
                if(i && a[ans.back()] == v[1]) f1 = false;
                if(a[v[0]] == v[1] && a[v[1]] == v[0]) f2 = false;
                if(i && a[ans.back()] == v[2]) f2 = false;

                if(f0) {
                    ans.push_back(v[0]);
                    st.erase(v[0]);
                    mp[a[v[0]]]--;
                    if(mp[a[v[0]]] == 0) mp.erase(a[v[0]]);    
                } else if(f1) {
                    ans.push_back(v[1]);
                    st.erase(v[1]);
                    mp[a[v[1]]]--;
                    if(mp[a[v[1]]] == 0) mp.erase(a[v[1]]);
                } else if(f2) {
                    ans.push_back(v[2]);
                    st.erase(v[2]);
                    mp[a[v[2]]]--;
                    if(mp[a[v[2]]] == 0) mp.erase(a[v[2]]);
                } else {
                    return vector<ll>(0);
                }
            } else if(i == 0) {
                ans.push_back(0);
                st.erase(0);
                mp[a[0]]--;
                if(mp[a[0]] == 0) mp.erase(a[0]);
            } else if(a[ans.back()] == mi) {
                ans.push_back(mi2);
                st.erase(mi2);
                mp[a[mi2]]--;
                if(mp[a[mi2]] == 0) mp.erase(a[mi2]);
            } else {
                ans.push_back(mi);
                st.erase(mi);
                mp[a[mi]]--;
                if(mp[a[mi]] == 0) mp.erase(a[mi]);
            }
        }

        // REP(i, n) cout << ans[i]+1 << (i==n-1 ? '\n': ' ');
        // cout << flush;
        return ans;
    };

    auto ret = solve();
    if(ret.size() == 0) cout << -1 << endl;
    else {
        REP(i, ret.size()) cout << ret[i]+1 << (i==n-1 ? '\n' : ' ');
        cout << flush;
    } 

    // auto naive = [&] {
    //     vector<ll> b(n);
    //     iota(ALL(b), 0);
    //     do {
    //         bool flag = false;
    //         REP(i, n-1) if(a[b[i]] == b[i+1]) flag = true;
    //         if(!flag) return b;
    //     } while(next_permutation(ALL(b)));
    //     return vector<ll>(0);
    // };

    // vector<vector<ll>> vec;
    // function<void(ll, vector<ll>)> dfs = [&](ll idx, vector<ll> v) {
    //     if(idx == n) {
    //         vec.push_back(v);
    //         return;
    //     }
    //     REP(i, n) if(i != idx) {
    //         v.push_back(i);
    //         dfs(idx+1, v);
    //         v.pop_back();
    //     }
    // };
    // vector<ll> v;
    // dfs(0, v);

    // for(auto v: vec) {
    //     v = a;
    //     auto nans = naive();
    //     auto ans = solve();
    //     if(ans != nans) {
    //         dump("--------");
    //         dump(a);
    //         dump(ans);
    //         dump(nans);
    //         dump("--------");
    //     }
    // }

    return 0;
}

Measured memory_bytes: 12544