#include <algorithm>
#include <cassert>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

const int BRUTE = 4;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<int> A(N + 1, 0);
    vector<int> degree(N + 1, 0);
    vector<bool> done(N + 1, false);

    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        degree[A[i]]++;
    }

    vector<int> B(N);
    priority_queue<int, vector<int>, greater<int>> remaining;
    priority_queue<pair<int, int>> degree_pq;

    for (int i = 1; i <= N; i++) {
        remaining.push(i);
        degree_pq.emplace(degree[i], i);
    }

    int initial = max(N - BRUTE, 0);
    int previous = 0;

    for (int i = 0; i < initial; i++) {
        while (done[degree_pq.top().second] || degree_pq.top().first != degree[degree_pq.top().second])
            degree_pq.pop();

        if (degree_pq.top().first >= N - i - 1) {
            int index = degree_pq.top().second;
            assert(!done[index]);
            B[i] = index;
        } else {
            while (done[remaining.top()])
                remaining.pop();

            int minimum = remaining.top(); remaining.pop();

            if (minimum == A[previous]) {
                while (done[remaining.top()])
                    remaining.pop();

                B[i] = remaining.top(); remaining.pop();
                remaining.push(minimum);
            } else {
                B[i] = minimum;
            }
        }

        previous = B[i];
        done[B[i]] = true;

        int reduce = A[B[i]];
        degree[reduce]--;
        degree_pq.emplace(degree[reduce], reduce);
    }

    vector<int> finish;

    while (!remaining.empty()) {
        if (!done[remaining.top()])
            finish.push_back(remaining.top());

        remaining.pop();
    }

    do {
        previous = initial == 0 ? 0 : B[initial - 1];
        bool good = true;

        for (int i = 0; i < (int) finish.size(); i++) {
            if (finish[i] == A[previous]) {
                good = false;
                break;
            }

            previous = finish[i];
        }

        if (good) {
            for (int i = initial; i < N; i++)
                B[i] = finish[i - initial];

            for (int i = 0; i < N; i++)
                cout << B[i] << (i < N - 1 ? ' ' : '\n');

            return 0;
        }
    } while (next_permutation(finish.begin(), finish.end()));

    cout << -1 << '\n';
}
