//
// Created by yamunaku on 2020/01/11.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;


struct SegmentTree{
    pair<int, int> ide = {-1, -1};

    inline void updatef(pair<int, int> &x, int y){
        x.first += y;
    }

    inline pair<int, int> queryf(pair<int, int> x, pair<int, int> y){
        return max(x, y);
    }

    int n;
    vector<pair<int, int>> node;

    SegmentTree(int sz, vi &v){
        n = 1;
        while(n < sz) n <<= 1;
        node.resize(2 * n - 1, ide);
        for(int i = 0; i < sz; i++) node[i + n - 1] = {v[i], i};
        for(int i = n - 2; i >= 0; i--) node[i] = queryf(node[i * 2 + 1], node[i * 2 + 2]);
    }

    void reset(int k){
        k += n - 1;
        node[k] = ide;
        while(k){
            k = (k - 1) / 2;
            node[k] = queryf(node[2 * k + 1], node[2 * k + 2]);
        }
    }

    void update(int k){
        k += n - 1;
        updatef(node[k], -1);
        while(k){
            k = (k - 1) / 2;
            node[k] = queryf(node[2 * k + 1], node[2 * k + 2]);
        }
    }

    pair<int, int> get(int a, int b, int k = 0, int l = 0, int r = -1){
        if(r < 0)r = n;
        if(r <= a || b <= l) return ide;
        if(a <= l && r <= b) return node[k];
        pair<int, int> xl = get(a, b, 2 * k + 1, l, (l + r) / 2);
        pair<int, int> xr = get(a, b, 2 * k + 2, (l + r) / 2, r);
        return queryf(xl, xr);
    }
};


int main(){
    // CFS;
    int n;
    cin >> n;
    vi a(n);
    vi deg(n);
    rep(i, n) cin >> a[i], a[i]--, deg[a[i]]++;
    if(n == 2){
        cout << -1 << endl;
        return 0;
    }
    if(n == 3){
        vi rem;
        rep(i, 3) rem.push_back(i);
        do{
            bool ok = true;
            if(a[rem[0]] == rem[1]) ok = false;
            if(a[rem[1]] == rem[2]) ok = false;
            if(ok) break;
        }while(next_permutation(all(rem)));
        rep(i, 3){
            cout << rem[i] + 1 << " ";
        }
        cout << endl;
        return 0;
    }
    SegmentTree seg(n, deg);
    heap<int> q([](const int &x, const int &y){
        return x > y;
    });
    rep(i, n) q.push(i);
    vi ans(n, -1);
    vi used(n, false);
    int ng = -1;
    rep(i, n - 4){
        pair<int,int> p = seg.get(0, n);
        if(p.first == n - i - 1){
            ans[i] = p.second;
            used[p.second] = true;
            ng = a[p.second];
            seg.reset(p.second);
            seg.update(a[p.second]);
            continue;
        }
        int x = q.top();
        q.pop();
        while(used[x]) x = q.top(), q.pop();
        if(x == ng){
            int tmp = q.top();
            q.pop();
            while(used[tmp]) tmp = q.top(), q.pop();
            q.push(x);
            x = tmp;
        }
        ans[i] = x;
        ng = a[x];
        seg.reset(x);
        seg.update(a[x]);
    }
    vi rem;
    rep(i, 4){
        int tmp = q.top();
        q.pop();
        while(used[tmp]) tmp = q.top(), q.pop();
        rem.push_back(tmp);
    }
    do{
        bool ok = true;
        if(ng == rem[0]) ok = false;
        if(a[rem[0]] == rem[1]) ok = false;
        if(a[rem[1]] == rem[2]) ok = false;
        if(a[rem[2]] == rem[3]) ok = false;
        if(ok) break;
    }while(next_permutation(all(rem)));
    rep(i, 4) ans[n - 4 + i] = rem[i];
    rep(i, n){
        cout << ans[i] + 1 << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 4984