#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int N; cin >> N;
    vector<int> A(N); for (auto &a : A) cin >> a, a--;
    map<int, int> M;
    for (auto a : A) M[a]++;
    if (N == 2) {
        cout << -1 << '\n';
        return 0;
    }
    set<int> S;
    for (int i = 0; i < N; i++) S.insert(i);
    vector<int> ans;
    int ban = -1;
    for (int i = 0; i < N; i++) {
        int rest = N - i;
        int choice = -1;
        for (auto item : S) {
            if (item == ban) {
                continue;
            }
            if (M[A[item]] == rest - 1 && S.count(A[item])) {
                choice = A[item];
                goto DONE;
            }
            choice = item;
            break;
        }
        if (rest == 3) {
            vector<int> B(begin(S), end(S));
            for (int i = 0; i < 3; i++) {
                int j = (i + 1) % 3;
                if (B[i] == A[B[j]] && B[j] == A[B[i]]) {
                    if (B[i] > B[j]) swap(B[i], B[j]);
                    choice = (B[i] != ban ? B[i] : B[j]);
                    break;
                }
            }
        }
        DONE:;
        ans.push_back(choice);
        S.erase(choice);
        ban = A[choice];
        M[A[choice]]--;
    }
    for (int i = 0; i < N; i++) {
        cout << ans[i] + 1 << " \n"[i == N - 1];
    }
    return 0;
}
