#include <cassert>
#include <functional>
#include <numeric>
#include <map>
#include <algorithm>
#include <vector>
#include <set>
#include <iostream>
using namespace std;

vector<int> bruteforce(int n, int *a) {
    vector<int> ans(n);
    iota(ans.begin(), ans.end(), 0);
    function <bool()> check = [&]() {
        for (int i = 1; i < n; i++) {
            if (a[ans[i-1]] == ans[i]) return false;
        }
        return true;
    };
    do {
        if (check()) return ans;
    } while (next_permutation(ans.begin(), ans.end()));
    return {};
}

int main() {
    int n; cin >> n;
    if (n == 2) { cout << "-1\n"; return 0; }
    int a[n], in_deg[n];
    fill(in_deg, in_deg+n, 0);
    // vector<int> ainv[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i]; a[i]--;
        in_deg[a[i]]++;
        // ainv[a[i]].push_back(i);
    }
    vector<int> ans;
    set<int> V;
    map<int, int> deg_cnt;
    for (int i = 0; i < n; i++) {
        V.insert(i);
        deg_cnt[in_deg[i]]++;
    }
    int u = -1;
    while (V.size() > 3) {
        while (deg_cnt.rbegin()->second == 0)
            deg_cnt.erase(prev(deg_cnt.end()));
        auto it = [&]() {
            if (deg_cnt.rbegin()->first == V.size() - 1) {
                for (int i = 0; i < n; i++)
                    if (in_deg[i] == V.size() - 1) return V.find(i);
            } else {
                auto it = V.begin();
                return (*it == u) ? next(it) : it;
            }
        }();
        const int v = *it;
        u = a[v];
        if (in_deg[u] > 0) {
            deg_cnt[in_deg[u]]--;
            in_deg[u]--;
            deg_cnt[in_deg[u]]++;
        }
        deg_cnt[in_deg[v]]--;
        in_deg[v] = 0;
        V.erase(it);
        ans.push_back(v);
    }
    for (int u : V) ans.push_back(u);
    do {
        if (n > 3 && a[ans[n-4]] == ans[n-3]) continue;
        if (a[ans[n-3]] == ans[n-2]) continue;
        if (a[ans[n-2]] == ans[n-1]) continue;
        break;
    } while (next_permutation(ans.end()-3, ans.end()));
    for (int x : ans) cout << x+1 << ' '; cout << endl;

    // vector<int> ans2 = bruteforce(n, a);
    // assert (ans2.size() == n);
    // for (int i = 0; i < n; i++) assert(ans[i] == ans2[i]);
}
