import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(x => x.to!int-1).array;

    auto ans = new int[](N);
    auto used = new bool[](N);

    auto hated = new SegmentTree!(Tuple!(int, int), (a,b)=>a[0]>=b[0]?a:b, tuple(0, 0))(N);
    foreach (i; 0..N) hated.assign(i, tuple(0, i));
    foreach (i; 0..N) hated.add(A[i], 1);

    auto pq = new BinaryHeap!(Array!int, "a > b");
    foreach (i; 0..N) pq.insert(i);

    DList!int tmp;

    foreach (i; 0..N-3) {
        bool ok = false;
        auto q = hated.query(0, N-1);
        if (q[0] == N - i - 1) {
            ans[i] = q[1];
            hated.assign(q[1], tuple(0, 0));
            hated.add(A[q[1]], -1);
            used[q[1]] = true;
            continue;
        }
        while (!pq.empty) {
            auto n = pq.front;
            pq.removeFront;
            if (used[n]) continue;
            tmp.insertBack(n);
            if (i != 0 && A[ans[i-1]] == n) continue;
            ans[i] = n;
            hated.assign(n, tuple(0, 0));
            hated.add(A[n], -1);
            used[n] = true;
            while (!tmp.empty) {
                auto m = tmp.front;
                tmp.removeFront;
                if (m != n) pq.insert(m);
            }
            ok = true;
            break;
        }
        if (!ok) {
            writeln(-1);
            return;
        }
    }

    bool ok() {
        foreach (i; 0..N-1) if (ans[i+1] == A[ans[i]]) return false;
        return true;
    }

    pq.dup.writeln;
    int[] rest;
    while (!pq.empty) {
        if (!used[pq.front]) rest ~= pq.front;
        pq.removeFront;
    }
    auto len = rest.length.to!int;

    do {
        foreach (i; 0..len) ans[N-len+i] = rest[i];
        if (ok()) {
            ans.map!(a => (a+1).to!string).join(" ").writeln;
            return;
        }
    } while(nextPermutation(rest));

    writeln(-1);
}

class SegmentTree(T, alias op, T e) {
    T[] table;
    int size;
    int offset;

    this(int n) {
        size = 1;
        while (size <= n) size <<= 1;
        size <<= 1;
        table = new T[](size);
        fill(table, e);
        offset = size / 2;
    }

    void assign(int pos, T val) {
        pos += offset;
        table[pos] = val;
        while (pos > 1) {
            pos /= 2;
            table[pos] = op(table[pos*2], table[pos*2+1]);
        }
    }

    void add(int pos, int val) {
        pos += offset;
        table[pos][0] += val;
        while (pos > 1) {
            pos /= 2;
            table[pos] = op(table[pos*2], table[pos*2+1]);
        }
    }

    T query(int l, int r) {
        return query(l, r, 1, 0, offset-1);
    }

    T query(int l, int r, int i, int a, int b) {
        if (b < l || r < a) {
            return e;
        } else if (l <= a && b <= r) {
            return table[i];
        } else {
            return op(query(l, r, i*2, a, (a+b)/2), query(l, r, i*2+1, (a+b)/2+1, b));
        }
    }
}